chipsworld
Board Regular
- Joined
- May 23, 2019
- Messages
- 164
- Office Version
- 365
Good day all...
I am experiencing something that I do not understand.
I have a simple data entry userform with a few text fields.
The issue is:
Form works great except after hitting the Apply button to run the code to update everything.
The last line of the code is to set the focus back to the first text field to do another item.
When it runs, everything works except for the set focus. I get the below error....
The crazy part is...after I hit debug and see that the line highlighted is the cyclecntfrm.upcttxt.SetFocus line. When I then click the run arrow on the ribbon, it works perfectly and sets the focus in the first txt field..
I am at a loss...
HEre is the code and form for that Sub...
the only fields set with a Tab Stop and the "Scan UPC Code" = 0, "Current System Inventory Qty" = 1, and "Correct Inventory Qty" = 2
I am experiencing something that I do not understand.
I have a simple data entry userform with a few text fields.
The issue is:
Form works great except after hitting the Apply button to run the code to update everything.
The last line of the code is to set the focus back to the first text field to do another item.
When it runs, everything works except for the set focus. I get the below error....
The crazy part is...after I hit debug and see that the line highlighted is the cyclecntfrm.upcttxt.SetFocus line. When I then click the run arrow on the ribbon, it works perfectly and sets the focus in the first txt field..
I am at a loss...
HEre is the code and form for that Sub...
the only fields set with a Tab Stop and the "Scan UPC Code" = 0, "Current System Inventory Qty" = 1, and "Correct Inventory Qty" = 2
VBA Code:
Dim user As String
Dim upcnum As String
Private Sub cmdaply_Click()
Dim lkup As String
Dim updwn As Double
lkup = upcnum
With ThisWorkbook.Sheets("Inventory")
Dim rw As Long, Fnd As Range
Set Fnd = .Range("A:D").Find(lkup, LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlPrevious)
If Not Fnd Is Nothing Then
rw = Fnd.Row
End If
If (Me.crnttxt.Value = Me.cortxt.Value) Or Me.cortxt.Value = "" Then
With ThisWorkbook.Sheets("CycleCount")
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row ' add transaction to "Transaction" sheet
rw1 = lastrow + 1
'add transaction to CycleCount worksheet
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "A").Value = Me.desctxt.Value
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "B").Value = Me.crnttxt.Value
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "C").Value = updwn
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "D").Value = Me.cortxt.Value
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "E").Value = user
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "F").Value = Now()
End With
Else 'make correction to Inventory sheet
updwn = Me.cortxt.Value - Me.crnttxt.Value 'calculate difference
ThisWorkbook.Sheets("Inventory").Cells(rw, "G").Value = ThisWorkbook.Sheets("Inventory").Cells(rw, "G").Value + updwn 'calculate new inventory balance
With ThisWorkbook.Sheets("CycleCount")
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row ' add transaction to "Transaction" sheet
rw1 = lastrow + 1
'add transaction to CycleCount worksheet
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "A").Value = Me.txtptnum.Value
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "B").Value = Me.desctxt.Value
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "C").Value = Me.crnttxt.Value
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "D").Value = updwn
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "E").Value = Me.cortxt.Value
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "F").Value = user
ThisWorkbook.Sheets("CycleCount").Cells(rw1, "G").Value = Now()
End With
End If
End With
Me.upcttxt.Value = ""
Me.desctxt.Value = ""
Me.crnttxt.Value = ""
Me.cortxt.Value = ""
Me.txtptnum.Value = ""
Me.txtuntiss.Value = ""
ThisWorkbook.Save
[B]cyclecntfrm.upcttxt.SetFocus[/B]
End Sub