Hi friend...,
See again.... i would like to create my Number ID with unique number where the number will start with PO100001, this mean PO is purchase order and 100001 is increment number. if you have any idea please let me know...
Public Function SetPO() As String
Dim db As Database
Dim rs As Recordset
Dim NewNr As Long
Set db = CurrentDb
Set rs = db.OpenRecordset("Table1", dbOpenTable)
rs.Index = "NumberID"
If rs.RecordCount <= 0 Then
SetPO = "PO100001"
Else
rs.MoveLast
NewNr = CLng(Mid(rs!NumberID, 3)) + 1
If NewNr <= 999999 Then
SetPO = "PO" & LTrim$(Str$(NewNr))
Else
MsgBox "NumberID too big"
SetPO = "********"
End If
End If
rs.Close
db.Close
Set db = Nothing
Set rs = Nothing
End Function
In NumberID control on a Form, set DefaultValue to SetP()
or
Private Sub Form_BeforeInsert(Cancel As Integer)
Me!NumberID = SetPO()
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.