format number generated by VB code

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

Guest

I have a number being generated by a VB code in a form, the number is a four
digit number based on the number previous. I need this number to have a
leading 0. For instance right now I can generate number 6001 but I need it
to appear as 06001. I have already tried formatting the field 00000, but
that isn't working.

The VB code I am using is:
Private Sub Form_Current()
If IsNull(QuoteNum) Then
QuoteNum = Nz(DMax("[QuoteNum]", "Quote"), 8490) + 1

Any help is much appreciated!
 
What is QuoteNum: a numeric field or a text field?

If it's numeric, you can't make it have preceding zeroes. That's simply a
display feature: with numeric fields, 6001 and 06001 are both the same
value.

If it's text, then try:

QuoteNum = Format(CLng(Nz(DMax("[QuoteNum]", "Quote"), 8490)) + 1, "00000")


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


m.sartele said:
I have a number being generated by a VB code in a form, the number is a
four
digit number based on the number previous. I need this number to have a
leading 0. For instance right now I can generate number 6001 but I need
it
to appear as 06001. I have already tried formatting the field 00000, but
that isn't working.

The VB code I am using is:
Private Sub Form_Current()
If IsNull(QuoteNum) Then
QuoteNum = Nz(DMax("[QuoteNum]", "Quote"), 8490) + 1

Any help is much appreciated!
 
Back
Top