Help with Userform

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
260
Office Version
  1. 2010
Platform
  1. Windows
VBA Code:
Private Sub CommandButton1_Click()
    Dim txtLabNo        As Variant, m As Variant
    Dim i               As Long
    Dim wsMaster        As Worksheet
   'lab number
    txtLabNo = Left(Me[COLOR=rgb(209, 72, 65)].[/COLOR][COLOR=rgb(65, 168, 95)]LabNumBOX[/COLOR], 7)
     If Not IsNumeric(txtLabNo) Then Exit Sub Else txtLabNo = Val(txtLabNo)
   'change master sheet name as required
    Set wsMaster = ThisWorkbook.Worksheets("DATA")
   'search column A
    m = Application.Match(txtLabNo, wsMaster.Columns(2), 0 
    If Not IsError(m) Then
            'post to master sheet
            wsMaster.Cells(CLng(m), 4).Value = "x"
            Me.LabNumBOX = ""
            LabNumBOX.SetFocus
    Else
   'inform user
        MsgBox txtLabNo & Chr(10) & "Record Not Found", 48, "Not Found"
           End If
   End Sub


So i have a userform that searches for a a Lab number in a Column A given the text in a Userform text box(LabNumBOX)
This lab number is from a bar code reader that has a carriage return as a default. The code above actioned by pressing a button.
How can i get the textbox to run automatically without having to press the button
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
that's the sort of thing i need . It moves the focus to the next button. However i would like it to continue as if that button was pressed
What happen if you put the code in TextBox1_Change?
 
Upvote 0
i afraid it doesnt work... i am a bit out of my depth

the bc reader scans the 7 digits and then has a carriage return by default
all i need is to scan the 7 digits and then perform the action without pressing a command button to start the action
 
Upvote 0
Sorry, I can't help you with this. Hope somebody else would step in.
 
Upvote 0
I have no experience with bc readers so probably can't solve this. However, even if you remove the messed up code (probably from trying to apply colours to the font in the code) it should still not compile as there is a missing ) in this line
m = Application.Match(txtLabNo, wsMaster.Columns(2), 0

Perhaps you could use a key event on the textbox and trap for the last key code that the scanner inputs. This may be 13. One trick would be to determine the best/correct event; perhaps KeyDown on the textbox and msgbox that key code to find out what that key code is:
msgbox KeyCode
KeyCode = False
If that turns out to be 13 then
VBA Code:
If KeyCode = 13 Then 'do something (or the opposite; If KeyCode <> 13 Then
    'do more stuff
    KeyCode = False
End If
I think you want to use =False if you raise a message box for any part of this, otherwise you might get caught in a loop by dismissing the msgbox. Not sure if you'd also need to remove the tab stop for any or all of the controls on the form. You might also need to disable events temporarily so that multiple key events or other updates don't create a loop of procedure calls.
 
Upvote 0
Private Sub CommandButton1_Click()
Dim txtLabNo As Variant, m As Variant
Dim i As Long
Dim wsMaster As Worksheet

'lab number
txtLabNo = Left(Me.LabNumBOX, 7)
If Not IsNumeric(txtLabNo) Then Exit Sub Else txtLabNo = Val(txtLabNo)

'change master sheet name as required
Set wsMaster = ThisWorkbook.Worksheets("DATA")

'search column A
m = Application.Match(txtLabNo, wsMaster.Columns(2), 0
If Not IsError(m) Then
'post to master sheet
wsMaster.Cells(CLng(m), 4).Value = "x"
Me.LabNumBOX = ""
LabNumBOX.SetFocus
Else
'inform user
MsgBox txtLabNo & Chr(10) & "Record Not Found", 48, "Not Found"
End If
End Sub

i have tried your suggestion but i did not get much further

My Form, at he moment has a text box and a submit button
what i need to do is drop the submit button and the "DO STUFF" to start after the text box populated with the scan which is a terminated with a carriage return
the barcoded number just sits there inactive
i seems that the text box is inert
 
Upvote 0
If you research this topic it seems to be a fairly common problem. If no one here can solve it, I guess that's what you'll have to do. I was able to capture Enter key press but again, I have no experience with bc readers, and I don't know what your last entered character is.
 
Upvote 0
so i have been digging around found how to do it by accident


Private Sub TextBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

List = 5
If KeyCode = Asc(vbCr) Then

Sheets("DATA").Cells(List, 2).Value = Left(Me.TextBox2, 7)
List = List + 1
Me.TextBox2.Value = ""

End If

End Sub

however, i cant get it to move on to the cell below... it just changes the content of Cells(5,2) .... i want to repeat an unknown number for bar-codes into 6,2 7,2 etc.

can anyone help
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,987
Members
449,093
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top