How to keep textbox in focus while also inputting data into table

ManIdk

New Member
Joined
Apr 25, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hey guys, I'm meddling in VBA, having lots of fun but I'm running into issues.

I'm attempting to use a barcode scanner to scan multiple items into a table. I've gotten everything to input where it should, but when I hit enter (scan button) it goes to the command button automatically. I have dozens of barcodes to scan, so it would be a hassle to have to walk over to my computer and press enter each time. I'm wondering if I can set it to either click "Submit" immediately once I scan something or if I can just have it set focus to my textbox at all times. Please let me know if there's more context needed. Code below

VBA Code:
Private Sub cmbSubmit_Click()

    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 14).End(xlUp).Row
    Cells(LastRow + 1, 14).Value = Me.tbxSN1
    Me.tbxSN1.Value = ""
    Cells(LastRow + 1, 13).Value = Me.cbxTechID
    Cells(LastRow + 1, 16).Value = Me.tbxDate

End Sub

Private Sub cmbClose_Click()

Unload Me

End Sub



Private Sub UserForm_Initialize()
   
    Me.cbxTechID.RowSource = "'Information'!A2:A10"
    
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Update:

I figured it out. The solution using BeforeUpdate, keeping the same code, and adding "Cancel = True"
I'm going to bed.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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