how can i change the numbers so they are my own customer numbers

S

SomethingMore

I want to have my own format for customer and project numbers, how do I do it?
 
A

Arvin Meyer [MVP]

Add a text or numeric field to the table, make it required, and make sure
that any foreign key field is the same data type.
 
J

John W. Vinson

I want to have my own format for customer and project numbers, how do I do it?

Use some datatype other than Autonumber, and manage the values and format
yourself.
 
S

SomethingMore

So, is there a way to set it up to automatically assign a customer number.
The format I want is yymm######. Thanks, Patty
 
K

Ken Sheridan

Patty:

Firstly the data type for the CustomerNumber column will need to be Text if
you want to store the leading zero of the year. It then depends on whether
you want the last six characters of the customer number to start from 000001
each month, or to be unique. For the former, in a form bound to the
Customers table put code along these lines in the form's BeforeInsert event
procedure:

Dim strYearMonth As String
Dim strCriteria as String
Dim varLastNumber as Variant

strYearMonth = Format(VBA.Date,"yymm")
strCriteria = "Left([CustomerNumber],4) = """ & strYearMonth & """"
varLastNumber = DMax("[CustomerNumber]", "[Customers]", strCriteria)

' add 1 to last customer for year/month, if any
If IsNull(varLastNumber) Then
Me.[CustomerNumber] = strYearMonth & "000001"
Else
Me.[CustomerNumber] = strYearMonth & _
Format(Right(varLastNumber,6)+1,"000000")
End If

If the last six characters of the customer number are unique:

Dim strYearMonth As String
Dim varLastNumber as Variant

strYearMonth = Format(VBA.Date,"yymm")
varLastNumber = DMax("[CustomerNumber]", "[Customers]")

' add 1 to last customer if any
If IsNull(varLastNumber) Then
Me.[CustomerNumber] = strYearMonth & "000001"
Else
Me.[CustomerNumber] = strYearMonth & _
Format(Right(varLastNumber,6)+1,"000000")
End If

Note that in a multi-user environment this could case conflicts if two or
more users are adding a new customer record simultaneously. Provided the
CustomerNumber column is indexed uniquely, however, this would raise an error
which could then be handled.

Ken Sheridan
Stafford, England
 

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

Similar Threads

DataBase 5
Populating foreign key fields? 2
Excel Conditional Formatting 1
Access Tidy up phone numbers 0
Access Auto Matching Duplicates? 0
Linking two tables 1
autonumber is entering duplicate numbers 2
How do I set up this Database? 1

Top