how do i change first characters on a text field ? (1 Viewer)

hullstorage

Registered User.
Local time
Today, 21:37
Joined
Jul 18, 2007
Messages
213
Hi all,

I have a form with a field called PartNumber these are entered from a barcode scanner by scanning barcodes on a box.

My problem is this:

When we scan a part number the barcodes actual part numbers are shown like this: PN321-ab55 but the actual part number we use is 321-ab55

So on scanning the barcode it produces PN first which is short for Part Number.

How do I when scanning into field remove the PN part of it so field only reads 321-ab55.

Also the boxes may have up to 10 different barcodes with different start letters or tracking number etc, so lets say the user scans the wrong barcode (barcode does not start with PN) maybe a beep is heard and a msgbox showing "you have scanned the wrong barcode, try again"

Many thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:37
Joined
May 7, 2009
Messages
19,242
put this in a moudle:
Code:
Public Function isChar(s As Variant) As Boolean
    Dim intAscii As Integer
    s = Left(s & "", 1)
    If Len(s) = 0 Then Exit Function
    intAscii = Asc(s)
    isChar = (intAscii >= 65 And intAscii <= 90)
    If Not (isChar) Then isChar = (intAscii >= 97 And intAscii <= 122)
End Function

and on the Change event of your control (the one that gets the barcode):
Code:
Private Sub [COLOR=Blue]Text0[/COLOR]_Change()
    Dim s As String
    s = [COLOR=Blue]Text0[/COLOR].Text & ""
    While isChar(Left(s, 1))
        s = Mid(s, 2)
    Wend
    Me![COLOR=Blue]Text0[/COLOR].Value = s
End Sub

Text0 should be replaced with correct name of your control.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:37
Joined
Sep 12, 2006
Messages
15,656
simply this sort of thing will do it.

Code:
 if left(nz(partnumber,""),2)="PN" then 
     partnumber = mid(partnumber,3)
 else
     msgbox("Wrong BARCODE scanned")
     'remedial action required
 end if
 

Users who are viewing this thread

Top Bottom