Increment portion of key

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table where the key is YYYY-xxx-zzz where YYYY is the year, xxx is a
building number which is obtained from a text field on the form and zzz is a
sequential number. What is the best way to determine what the next sequence
should be? Table name is tblMOCform, key field is MOCID and building number
text field is txtBuilding.
Thanks
Marnie
 
This should do the trick maybe some small mistakes. I didn't test the code.

public function GetKey() as string
dim strKey as string
dim strPrefix as string
dim lSequence as long

lsequence=0
strPrefix=yyyy & "-" & txtBuilding & "-"
strkey=nz(dmax("MOCID","tblMOCform","MOCID LIKE '" & strPrefix & "*'"))

if strkey<>"" then
lsequence=val(mid(strkey,len(strprefix)+1))
end if
strkey=strprefix & format(lsequence+1,"0000#")

GetKey=strKey

End Function

- Raoul
 
That did it! Thank you very much!
Marni

JaRa said:
This should do the trick maybe some small mistakes. I didn't test the code.

public function GetKey() as string
dim strKey as string
dim strPrefix as string
dim lSequence as long

lsequence=0
strPrefix=yyyy & "-" & txtBuilding & "-"
strkey=nz(dmax("MOCID","tblMOCform","MOCID LIKE '" & strPrefix & "*'"))

if strkey<>"" then
lsequence=val(mid(strkey,len(strprefix)+1))
end if
strkey=strprefix & format(lsequence+1,"0000#")

GetKey=strKey

End Function

- Raoul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top