check string length and run code...

bwyrwitzke

Registered User.
Local time
Today, 15:48
Joined
Nov 11, 2002
Messages
50
Dumb question here... I'm scanning a 6 character barcode into an unbound text box. Once the barcode is scanned, the user has to hit a button to copy the data into a table. I'm trying to automate the process so the user does not have to do anything once the unbound text box contains the 6 characters.

I've tried using "len" to measure the length of the string, but it only updates when I move out of the text box then move back in. Any help here would be appreciated.

FYI: I'm entering the barcode info manually - the scanner is at the office...

Bruce
 
Use the On Change property of the text box to trigger an action once the text box has six characters. For example, in the Code Module for a form with a textbox named txtInput into which the barcode data will be scanned, insert the following code:
Code:
Private Sub txtInput_Change()
    Dim strInput As String
    ' strInput will contain the barcode-scanned data
    If Len(Me.txtInput.Text) = 6 Then
        strInput = Me.txtInput.Text
        '
        ' whatever action code you want in here
        '
    End If
End Sub
See if this method works for you.
 
still doesn't work...

My code looks similar

Code:
 Private Sub BarCodeID_Change()
     If len(Me.BarCodeID) = 6 Then
         msgbox "The string is formatted"
     End If
End Sub

I'm using the message the box as a place holder until I can get it to recognize the changes in the text box. At this point, I have to move the focus away from BarCodeID and then return it before it recognizes any changes to the length of Me.BarCodeID. Thanks for trying - any other ideas?

Bruce
 
I can't read...

I missed the ".text" on the end of me.barcodeID. Looks to be working now. Thanks for the help!

Bruce
 
You're welcome. Next time, please try reading ALL of my post before leaping to conclusions :)
 

Users who are viewing this thread

Back
Top Bottom