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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Unique ID Number?

Status
Not open for further replies.

haj1503

Technical User
May 29, 2001
56
0
0
MY
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...

best regard.
 
Look at my point of view:

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 = &quot;PO100001&quot;
Else
rs.MoveLast
NewNr = CLng(Mid(rs!NumberID, 3)) + 1
If NewNr <= 999999 Then
SetPO = &quot;PO&quot; & LTrim$(Str$(NewNr))
Else
MsgBox &quot;NumberID too big&quot;
SetPO = &quot;********&quot;
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top