Barcode Reader and leading zeros

  • Thread starter hcso via AccessMonster.com
  • Start date
H

hcso via AccessMonster.com

Hello.

We have a barcode reader that scans the bar code of vehicles that come in. It
scans a seven digit number into a field in a form however I only need five.
I'd like to make it so that when a code is scanned, those two leading zeros
automaticly come off. Is this possible and what steps would I take to get
there? Is it an event I set up on the field or some type of macro? I'm a
complete newbie so bear with me.
 
B

BruceM

If it's always a number (i.e. no letters or other non-number characters
including spaces) you should be able to store it as a number, which would
remove the leading zeros. If it is scanned as text (which is probably a
better idea than storing it as a number since it allows for other characters
in the field, which may be the case some day if it is not already), and it
is always a seven character string from which you need the rightmost five
digits, you could go ahead and store the number (text) as it comes in, but
display it without the zeros. In the Control Source of an unbound text box
in a form or report:
=Right([YourField],5)
Similarly, in an empty column of a query in design view:
ShortNum: Right([YourField],5)

Use your actual field name, and use whatever name you like in place of
ShortNum.

There are other options, depending on your specific needs, but in general
they involve how the number is displayed rather than how it is stored.
 
H

hcso via AccessMonster.com

Sorry I failed to mention that is a text field. It has to be since we have
other alphanumeric values that go into that field.
 
J

John W. Vinson

Hello.

We have a barcode reader that scans the bar code of vehicles that come in. It
scans a seven digit number into a field in a form however I only need five.
I'd like to make it so that when a code is scanned, those two leading zeros
automaticly come off. Is this possible and what steps would I take to get
there? Is it an event I set up on the field or some type of macro? I'm a
complete newbie so bear with me.

If you want to *always* strip off the first two characters (whether or not
they are zeros) and store only five in the Text field, you can use VBA code in
the AfterUpdate event of the textbox:

Private Sub textboxname_AfterUpdate()
Me!textboxname = Right(Me!textboxname, 5)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top