Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to prevent Zeros auto-deletion ?!

Status
Not open for further replies.

Jonath

Technical User
Jul 13, 2007
27
FR
Greetings,

I have a Table "ENQUETEURS" with a field "NUMBER"(primary key)

Format of this field is ?#########
where ? is A for french people
B for the rest of europe
C for the rest of the world
and # is the number (000000001, 00000002....etc)

I have a form with a control that allows the user to choose nationality, so that the new record gets a number automatically

On the On_Change event of the control, I wrote:

Code:
..'for french people
dim number
number = "A" & Mid(Dmax("NUMBER","ENQUETEURS","[NUMBER] between 'A00000000' and 'A999999999'"),2,9)+1
..

BUT with that I get for instance: A45
whereas I want A000000045...

Any idea how to keep the zeros?!

Thanks in advance.
Jonath
 
Code:
..'for french people
dim number
number = "A" & [i]format([/i]Mid(Dmax("NUMBER","ENQUETEURS","[NUMBER] between 'A00000000' and 'A999999999'"),2,9)+1[i],"000000000")[/i]
..
 
Ye I tried that already, but it didn't work.

Anyway, thanks for your answer, I make it work like this:

Code:
dim number
dim zeros
dim breaker
dim k
zeros=""
breaker=0

for k=1 to 9
if mid(mid(Dmax("[NUMBER]","ENQUETEURS","[NUMBER] between 'A000000000' and 'A999999999'"),2,9),k,1)=0 and breaker = 0 then
 zeros = zeros & "0"
 else: breaker=1
 end if
next

number= "A" & zeros & Mid(Dmax("[NUMBER]","ENQUETEURS","[NUMBER] between 'A000000000' and 'A999999999'"),2,9) +1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top