I have a userform with a button and a textbox; on the form activate event the focus is set to the textbox. The user will be using a barcode scanner to scan data into the textbox. On the AfterUpdate event of the textbox a routine runs to verify the data they scanned in. If all is well, the routine then prints a label with more barcodes to be verified.
I have the button and textbox tabstop set to true; these the only two controls on the userform with their tabstop property set to true.
The goal it to have the user scan a barcode, then the AfterUpdate event code runs, then the focus is returned to the textbox for it receive the next bit of data. BTW, the only purpose of the button is to offer the user a way to manually set the focus back to the textbox.
After several of the barcodes are scanned a label is printed, then the barcodes on these labels are also scanned; i.e. the label is printed in the middle of the routine). Everything works great as in the focus gets returned to the textbox, until it prints the label. I have tried everything I can find on the web to get the focus back to the textbox after the label prints but have not been successful.
I have tried Sendkeys, calling the click event of the button at the end of the textbox AfterUpdate routine, plus other things.
What always seems to happen is the focus hangs at the button. Manually clicking the button moves the focus to the textbox but calling the same click event from the AfterUpdate event DIRECTLY AFTER PRINTING THE LABEL just leaves the focus at the button, other times it does move the focus to the textbox.
I cannot post all of the code for propriety reasons but ask and I'll post what I can. Any help will be greatly appreciated!
TD
BUTTON CODE:
Me.txtInput.SetFocus
AfterUpdate Label printing code:
Call PrintLabel()
Module ModMain:
PrintLabel ():
'print label code
'set label sheet as activesheet
ThisWorkbook.Sheets("ABC").Activate
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0.15)
.BottomMargin = Application.InchesToPoints(0)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
End With
Application.PrintCommunication = True
Sheets("ABC").PrintOut
I have the button and textbox tabstop set to true; these the only two controls on the userform with their tabstop property set to true.
The goal it to have the user scan a barcode, then the AfterUpdate event code runs, then the focus is returned to the textbox for it receive the next bit of data. BTW, the only purpose of the button is to offer the user a way to manually set the focus back to the textbox.
After several of the barcodes are scanned a label is printed, then the barcodes on these labels are also scanned; i.e. the label is printed in the middle of the routine). Everything works great as in the focus gets returned to the textbox, until it prints the label. I have tried everything I can find on the web to get the focus back to the textbox after the label prints but have not been successful.
I have tried Sendkeys, calling the click event of the button at the end of the textbox AfterUpdate routine, plus other things.
What always seems to happen is the focus hangs at the button. Manually clicking the button moves the focus to the textbox but calling the same click event from the AfterUpdate event DIRECTLY AFTER PRINTING THE LABEL just leaves the focus at the button, other times it does move the focus to the textbox.
I cannot post all of the code for propriety reasons but ask and I'll post what I can. Any help will be greatly appreciated!
TD
BUTTON CODE:
Me.txtInput.SetFocus
AfterUpdate Label printing code:
Call PrintLabel()
Module ModMain:
PrintLabel ():
'print label code
'set label sheet as activesheet
ThisWorkbook.Sheets("ABC").Activate
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0.15)
.BottomMargin = Application.InchesToPoints(0)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
End With
Application.PrintCommunication = True
Sheets("ABC").PrintOut