Autonumber

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

Guest

I would like a database in which the customer number is a random, integer
number six digits in length?

I would like this to automatically be created for me when creating a new
record.

How can I do this?

Daniel
 
There might be a better answer, but you can use that
Create a table with a field that is autonumber, add to the table 100000
records, and then delete them, don't run compact, and the next records you
will insert will be six digits

Function AddNumber()
Dim MyDB As Database, MyRec As Recordset, I As Long
Set MyDB = CodeDb
Set MyRec = MyDB.OpenRecordset("MyTable")

For I = 0 To 100000
MyRec.AddNew
MyRec!MyValue = ""
MyRec.Update
Next I
DoCmd.RunSQL "Delete * From MyTable"
End Function
 
If you are using a form to drive your table a good way round it would be to
set the default value of the text box to - Dmax(insert your info)+1
You will need to add a test record of 99,999 before you start which may
present some problems later, but just an idea.
 
Or better,
I have just been sent this from another thread by "rick B"-
To be inserted to the before update event -

If IsNull(Me.ID) = True Then
Me.ID = Nz(DMax("ID", "TableName"), 0) + 1
End If

It would change to -

If IsNull(Me.ID) = True Then
Me.ID = Nz(DMax("ID", "TableName"), 99999) + 1
End If
 

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