Triming a letter from barcode..

G

GregB

On the boxes I have come in an extra "S" is inlcuded on in the barcode when
compared to the barcode on the item itself.
I scan stuff in by the box and scan stuff out by the item

I am trying to set an onclose event on a form utilizing vba to trim of the
"s" if there is an "s"

the field is called barcode
I know to use an IFF statement but can not get it right..
What would the code look like?

Thanks!
 
R

Rick Brandt

GregB said:
On the boxes I have come in an extra "S" is inlcuded on in the
barcode when compared to the barcode on the item itself.
I scan stuff in by the box and scan stuff out by the item

I am trying to set an onclose event on a form utilizing vba to trim
of the "s" if there is an "s"

the field is called barcode
I know to use an IFF statement but can not get it right..
What would the code look like?

Thanks!

Form Close is the wrong event. Either use AfterUpdate of the control or
BeforeUpdate of the form.

If Right(Me.BarCode,1) = "S" Then
Me.BarCode = Left(Me.BarCode, Len(Me,Barcode)-1)
End If

Extra characters on the end of a barcode are usually check-digits and for
your scanner to "see" them as characters in the output it would have to be
set up for the wrong barcode type. Also, check-digits are seldom always the
same character so your logic might not work as you expect.
 
A

Allen Browne

The Close event of the form is too late.
Use the AfterUpdate event procedure of the text box.

Something like this:

Private Sub barcode_AfterUpdate()
If Me.barcode Like "?*S" Then
Me.barcode = left(Me.barcode, len(Me.barcode) - 1)
End If
End Sub
 
K

Klatuu

Is it possible there could be a valid s on the end of your bar code so that
rather than abcdefss you want abcdefs as a result?

If so, you can still use either of the suggested solutions except you would
need to test for the last two characters being "ss"
 
G

GregB

Thanks Guys, sorry for the late reply I was on vacation. Hopefully you still
will look at this.

I trired Allens and Ricks method but it would not work...
And the S is on the begining of the barcode. S#########

The code you produced me dosn't proivde any errors it just dosn't do
anything... Of course I tried putting in serial numbers with an S at the
end.... still nothing?

Whats going on?

THanks
 
A

Allen Browne

Private Sub barcode_AfterUpdate()
If Me.barcode Like "S?*" Then
Me.barcode = mid(Me.barcode, 1)
End If
End Sub
 
G

GregB

nothing happens Allens...???

Allen Browne said:
Private Sub barcode_AfterUpdate()
If Me.barcode Like "S?*" Then
Me.barcode = mid(Me.barcode, 1)
End If
End Sub
 
K

Klatuu

I think Allen intended:
If Me.barcode Like "S?*" Then
Me.barcode = mid(Me.barcode, 2)
End If
End Sub

2 instead of 1. 1 returns the entire string.
 

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