Mick Peters
Board Regular
- Joined
- May 18, 2015
- Messages
- 93
Hi I have a user form with 3 input text boxes which is only allowed to use inputs from a barcode scanner , no keyboard no mouse. For the most part it works and people scan in and out without issue. Sometime however it is as if the scanner forgets to send the Enter that is programed at the end of each scan. This leaves the user unable to scan anything into the next text field and anything else scanned just adds on to the end of the first scan and still no enter. I thought I had a solution, using the on change event, as the on exit event is not triggered, by counting the number of letters in the text box and if it exceeds a certain amount then close and re open the user form. This is all I have to do to fix it when I am called to it and attach the keyboard and mouse. I have used the below code and it closes and re opens the form OK but the focus is in text box 2 (txtLocation)not text box 1 (txtName) as per the (now commented out) code. So I changed it to the below so it would tab twice once opened, this would move it from Textbox 2 to text box 1 but that also does not work. I have a Private Sub UserForm_Initialize() that is used at the first start of the form when the spread sheet is opened but that fails if I do an Application.Run saying that the values are no optional. Given the choice I would prefer to call the Private Sub UserForm_Initialize() after closing as that has more detail about the form settings in it
Private Sub UserForm_Initialize()
Thank you for reading , Any help would be greatly appreciated.
Thanks
Mick.
Code:
Private Sub txtName_Change()
If Len(TxtName.Text) > 9 Then
Unload Ureg
Call Save
Application.WindowState = xlMinimized
Ureg.Show
'Ureg.txtName.SetFocus
Ureg.Repaint
Application.SendKeys "{TAB 2}", True
'Ureg.txtName.SetFocus
Else
Exit Sub
End If
End Sub
Private Sub UserForm_Initialize()
Code:
Private Sub UserForm_Initialize()
With Application
.WindowState = xlMaximized
Zoom = Int(.Width / Me.Width * 100)
Width = .Width
Height = .Height
End With
txtDate.TextAlign = fmTextAlignCenter
TxtName.TextAlign = fmTextAlignCenter
txtLocation.TextAlign = fmTextAlignCenter
txtDirection.TextAlign = fmTextAlignCenter
TxtLastScan.TextAlign = fmTextAlignCenter
txtDate.Value = Format(Date, "dd/mm/yyyy")
Ureg.TxtName.SetFocus
End Sub
Thank you for reading , Any help would be greatly appreciated.
Thanks
Mick.
Last edited: