I'm creating a function that will autoincrement a purchase order number. The number is the logged in users initials followed by four numbers (eg. JC0001). How would I go about determining the highest existing number with the prefix of the person who is creating the new order?
Thanks, Justin
Here is my code, I apologize if it is a bit elementary:
[CODE=vb]Public Function GeneratePONumbe r()
Dim MyInitials, MyName, MyNames
Dim strFname, strLname, strInitials As String
Dim intHighPO As Integer
'INITIAL GENERATOR
'Determines who is logged in, and generates user's initials
strFname = DLookup("userna me", "users", "userid = " & intAuthUserId)
strLname = DLookup("userla stname", "users", "userid = " & intAuthUserId)
MyNames = Split(strFname & " " & strLname, " ")
For Each MyName In MyNames
If Len(MyName) > 0 Then MyInitials = MyInitials & UCase(Left(MyNa me, 1))
Next
'END INITIAL GENERATOR
For Each OrderPONumber In orders
'FIND HIGHEST PO NUMBER BEGINNING WITH MyInitials
Next
'ADD INITIALS AND LAST PO NUMBER+1
strNewPONumber = MyInitials & intHighPO + 1
End Function[/CODE]
Thanks, Justin
Here is my code, I apologize if it is a bit elementary:
[CODE=vb]Public Function GeneratePONumbe r()
Dim MyInitials, MyName, MyNames
Dim strFname, strLname, strInitials As String
Dim intHighPO As Integer
'INITIAL GENERATOR
'Determines who is logged in, and generates user's initials
strFname = DLookup("userna me", "users", "userid = " & intAuthUserId)
strLname = DLookup("userla stname", "users", "userid = " & intAuthUserId)
MyNames = Split(strFname & " " & strLname, " ")
For Each MyName In MyNames
If Len(MyName) > 0 Then MyInitials = MyInitials & UCase(Left(MyNa me, 1))
Next
'END INITIAL GENERATOR
For Each OrderPONumber In orders
'FIND HIGHEST PO NUMBER BEGINNING WITH MyInitials
Next
'ADD INITIALS AND LAST PO NUMBER+1
strNewPONumber = MyInitials & intHighPO + 1
End Function[/CODE]
Comment