formatiing numbers?

Maclain

Registered User.
Local time
Today, 15:56
Joined
Sep 30, 2008
Messages
109
Afternoon all,

I'm trying to get an invoice number field to auto generate the next number, keeping the format as "00000"

this is what I have, which gets the next number but drops the leading 0

Code:
Private Sub Customer_AfterUpdate()
 If Len(Me.[InvoiceNumber] & vbNullString) = 0 Then
    Me.[InvoiceNumber] = (DMax("[InvoiceNumber]", "[tblInvoiceNumber]") + 1)
    DoCmd.RunCommand acCmdSaveRecord
End If
End Sub
invoice numbers are 04024, 04025 etc

any ideas how I keep the formatiing?
 
Use the Format function maybe?
Code:
? Format(0, "00000")
00000
? Format(425, "00000")
00425
 
I've actually tried that, but can't figure out how to get it to work..

Code:
 Private Sub Customer_AfterUpdate()
 If Len(Me.[InvoiceNumber] & vbNullString) = 0 Then
    Me.[InvoiceNumber] = (DMax("[InvoiceNumber]", "[tblInvoiceNumber]") + 1 & format([InvoiceNumber], "00000"))
    DoCmd.RunCommand acCmdSaveRecord
End If
End Sub
Doesn't give me the desired result.
 
Doesn't give me the desired result.
Because you need to format the Number you wish to use. Not just add the format to the end.
Code:
Private Sub Customer_AfterUpdate()
    If Len(Me.[InvoiceNumber] & vbNullString) = 0 Then
        Me.[InvoiceNumber] = [COLOR=Red][B]Format([/B][/COLOR]DMax("[InvoiceNumber]", "[tblInvoiceNumber]") + 1[COLOR=Red][B],  "00000")[/B][/COLOR]
        DoCmd.RunCommand acCmdSaveRecord
    End If
End Sub
What is the Data Type of Invoice Number? The above might Err if it is Number.
 
No problem ! Good luck. :)

PS: Thanks for giving my 1,800th Thanks ! :D
 

Users who are viewing this thread

Back
Top Bottom