Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prefix ID fields

Status
Not open for further replies.

Evotwo

Technical User
Mar 1, 2002
7
0
0
GB
I have several ID fields that require incrementing by 1 and then require the prefix of a letter. For example P00067, HI10025 some of these fields gain their prefix from other fields. Others require the prefix to add meaning to the unique id number. I would imagine that Dmax would work if I remove the prefix and then add back in but is there an easier way to do this. I haven't got a clue with adding a prefix from another field

Any help is appreciated
Thanks in advance
 
The other challenge will be adding back the correct amount of leading zeros.. ..

Try this:-
Code:
Dim strInputIndex As String
Dim intCount As Integer
Dim intNewIndex as Integer
Dim strPrefix As String
dim strZerosAndNewIndex As String
strInputIndex = the last index issued

intCount = 1
While Not IsNumeric(Right(strInputIndex), Len(strInputIndex) - intCount)
    intCount = intCount+1
Wend

intNewIndex = Right(strInputIndex), Len(strInputIndex) -intCount)

' This bit gets the prefix from another field
' Assuming it is in the form [SomePrefixLetters][ANumber]
intCount = 1
While Not IsNumeric(Right(SourceFieldOfPrefix), Len(SourceFieldOfPrefix) - intCount)
    intCount = intCount+1
Wend
strPrefix = Left(SourceFieldOfPrefix,intCount)

' This bit populates strZeros with the appropriate number of zeros
strZerosAndNewIndex  = Trim(CStr(intNewIndex))
While len(strZerosAndNewIndex)> RequiredNumberOfChars
    strZerosAndNewIndex = "0" & strZerosAndNewIndex 
Wend


' And Finally
NewIdField = strPrefix & strZerosAndNewIndex



'ope-that-'elps

G LS
 
Thanks LittleSmudge for the rapid reply I am going to try and implement your sugestion later and will let you know how it goes.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top