Discussion Locked

VB6: Acting on a recordset

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a table of physicians that I need to assign a two character suffix. I will be exporting this data to a UNIX application that only allows for 2 characters in that field. The primary field is the tax-id and the suffix is to identify that physician. This way they can all share the same TIN. I had programmed this in Paradox 3.x and did SCAN after a sort. I went through comparing each record to see if the TIN matched the previous TIN or not. Here's a sample of how it should look:
123456789-01
123456789-02
123456789-03
234567890-01
234567890-02
345678901-01
456789012-01

How do I program this in VB? The data is in Access97 currently. Thank you!!!!
Patrick

3 replies

by peyison

Patrick,

Try something like this:

Assuming you have a created a recordset already (should be sorted on "YourField"), and have opened a file as iFile:

Dim iCounter as Integer
Dim sCurrentTIN as String
Dim sLastTIN as String

Do Until oRst.EOF
sCurrentTIN = oRst!YourField
If sCurrentTIN = sLastTIN Then
iCounter = iCounter + 1
Else
iCounter = 1
sLastTIN = sCurrentTIN
End If
Print #iFile, sCurrentTIN & "-" & Format$(iCounter, "00")

oRst.MoveNext
Loop

Hope this helps.

This discussion is closed to new replies.