PDA

View Full Version : Need sequential, formatted number



Dave 14867
01-01-2017, 05:17 AM
Hello all, a newbie here with a simple issue but I can't remember how to do it.

I need a sequential number to be generated, which I have done with DMax(), but I also need to now take that number and "pad" it with leading "0's" so I end up with a 4 digit number and save it as a string, example, I generate the number 143, but what I really need is 0143 and need to save it as a string, text actually.

How can I do this?

I am using Access 2007, Windows 7

Thanks in advance for you assistance

OTWarrior
01-05-2017, 09:21 AM
Have you converted the original number (143) into a string, then added the 0's to the beginning of it?

Something like:


Newvalue = "0" & String(value)

Dave 14867
01-05-2017, 02:17 PM
OTWarrior,

Below is the code I am using and thought it was working OK but further testing proved it wasn't. I also want the number (string) to be put into the "Number" field which I can't seem to get it to do, I am obviously missing something.

Me.Number = Nz(DMax("txtPosition", "NCR Table") + 1)
Me.[txtPosition] = Format("[txtPosition]", "NCR Table", "0000")


Me.[New NCR Number] = "50-09-0" + [Number]

Any help would be greatly appreciated.

Thanks

Dave