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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ignore leading 0 in feild

Status
Not open for further replies.

Zorro1265

Technical User
Nov 14, 2000
181
US
I have a number feild that some users enter preceding zeros before and others do not. Is there a way I can make access ignore zeros in the beginning of a number? For example 001234 would just store 1234 and 09876 would just store 9876.
 
Hello Zoro!
Your best bet would be to investigate the "Input Mask" property that can be set on the field on your form. By your example you only want 4 numbers. You can set an input mask to any arrangement you choose, basically forcing the user to only input (in your case the quantity of numbers) that you establish. Go to the input mask property "field" of any field on your form and hit F1. There's tons of examples and variations. Good luck, Gord
ghubbell@total.net
 
I have the mask set to a max number of 8 digits but some folks are adding leading zeros to give that 8 digit max all the time. Others do not. I would prefer to ignore them if entered on exit of the feild. Sort of the why type it if you dont have to.
 
Hi Zorro,
I'm a little puzzled. Is this field a number field, or a text field that just always contains numbers?

If it's a number field, it should automatically chop off any leading zeros.. they don't qualify as part of a number.

Assuming it's a text field, you could do the input mask as ghubbell says (definitely easiest if it works), or if they don't all have the same number of digits, you could set the AfterUpdate event to chop off leading zeros via code.
 
Its a text field that always has numbers, I was adivsed to use text fields if I never planned on doing any math with the numbers. They are ID number fields. There is an 8 digit maximum but it could be anything up to that maximum. Example 01234567, 00123456, 00012345.
 
Odd advice I find...how do you sort things? Gord
ghubbell@total.net
 
Ok, here is a way if you want to avoid input masks, to chop off the leading zeros via code:

In the control's AfterUpdate event, place the following code:

(this assumes the textbox control's name is txtID. You'd need to modify it for your needs)

dim strLetter as string, strID as string, i as integer

strID = txtID.value

i = 0

do until mid(strID,i,1)<>&quot;0&quot; or i>len(strID)
i=i+1
loop

strID = Right(strID, len(strID) - i)

txtID.value = strID


Please let me know if you have any questions on how to do this, or if you run into any problem with the code.
 
ghubbell raises a very good point.. I personally find if you want to use text fields, you should have the code add leading zeros if they're not provided. This will maintain sorting capability.

To add leading zeros (up to 8 characters), see thread181-65570 for sample code which you can modify for your needs..
 
Or just convert the text field to a Long Integer (which will remove any leading zeros) and then back to a string for storage:

CStr(CLng(txtField.text))

This assumes that the mask only allows for numeric input or that the validity of the value in the text field has already been checked.



Mark
 
I guess my advisor was less than helpful about using a text field huh? I suppose there is no reason I cant change this to a number field and avoid all this is there? I think I will try that on a copy of my database and see what happens. It sounds like I am making things a lot more complicated than they need to be.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top