W
wullieb1
Guest
Autogenerate a number but with a difference
Folks,
Newbie to this forum so please be gentle. I am a relative newbie to acces but i seem to be picking it up quite quickly.
My problem is this:
I have an enquiry form made up and a button on the form that will generate a number by using the following code:
This code works perfectly and generates a new enquiry number for me.
The end user now wants to change the format of the number to read like this 06-0001, whereas before i was using 60001.
What i would like to know is there anyway i can increment the last 4 digits only? i.e remove the first 3 digits, 06-, increment the 0001 by 1 then reassemble them back together.
Thanks for your help.
Folks,
Newbie to this forum so please be gentle. I am a relative newbie to acces but i seem to be picking it up quite quickly.
My problem is this:
I have an enquiry form made up and a button on the form that will generate a number by using the following code:
Code:
Private Sub EnqGen_Click()
On Error GoTo Err_EnqGen_Click
Me![Enquiry Number] = NewEnqNum()
Me![Customer Name].SetFocus
Me![Enquiry Number].Enabled = False
Exit_EnqGen_Click:
Exit Sub
Err_EnqGen_Click:
MsgBox "Error " & Err & ": " & Error$
Resume Exit_EnqGen_Click
Exit Sub
End Sub
Public Function NewEnqNum() As Long
On Error GoTo NextEnq_Err
Dim lngNextEnq As Long
lngNextEnq = DMax("[Enquiry Number]", "Enquiry") + 1
NewEnqNum = lngNextEnq
Exit_NewEnqNum:
Exit Function
NextEnq_Err:
MsgBox "Error " & Err & ": " & Error$
Resume Exit_NewEnqNum
Exit Function
End Function
This code works perfectly and generates a new enquiry number for me.
The end user now wants to change the format of the number to read like this 06-0001, whereas before i was using 60001.
What i would like to know is there anyway i can increment the last 4 digits only? i.e remove the first 3 digits, 06-, increment the 0001 by 1 then reassemble them back together.
Thanks for your help.
Last edited: