UserForm On 2nd Scan, Cycle to next

Bluesguy07

New Member
Joined
Mar 11, 2016
Messages
28
Good morning. Apparently my last question was a bust and was probably confusing. Luckily I figured out how to do what I needed. Now, My issue is that I want to have the form close and reopen (I think that's the easiest avenue to take) after the user scans data into the 2nd text box.

Currently, there are 2 text boxes. The first one is for Serial Number, the 2nd one is for Weight. I have two command buttons, one to progress to the next set, and one to close the form.

The two possible options are as follows.

User scans into both text boxes, and it automatically adds the Serial Number and Weight - progressing to the next set of data... or...
User scans into both text boxes, and it closes and reopens the form.

Either way, I'm fine with.

My current code is below

Code:
Private Sub cmdAdd_Click()
    Dim LastRow As Long
    Dim ws As Worksheet: Set ws = Sheets("Sheet1")
    LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    ws.Range("A" & LastRow + 1).Value = txtSN.Text
    ws.Range("B" & LastRow + 1).Value = txtWeight.Text
    txtSN.Text = ""
    txtWeight.Text = ""
End Sub


Private Sub cmdClose_Click()
    Unload frmSNWeight
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I figured it out. I just needed to add a set focus, and it ended up doing what I wanted to do. I also changed the private sub to _Enter instead of _Click

Code:
Private Sub cmdAdd_Enter()
    Dim LastRow As Long
    Dim ws As Worksheet: Set ws = Sheets("Sheet1")
    LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    ws.Range("A" & LastRow + 1).Value = txtSN.Text
    ws.Range("B" & LastRow + 1).Value = txtWeight.Text
    txtSN.Text = ""
    txtWeight.Text = ""
    txtSN.SetFocus

End Sub

Private Sub cmdClose_Click()
    Unload frmSNWeight
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,004
Messages
6,128,223
Members
449,435
Latest member
Jahmia0616

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