janderson055
New Member
- Joined
- Feb 7, 2012
- Messages
- 30
I have a userform that allows me to add a new employee to a sheet, which adds some info to the sheet itself and creates a new sheet with that employees name on it. After all this process I try to setfocus back to the userform on the first text box, just by using myform.txtbox.setfocus yet it doesn't seem to work. Any help would be great.
Code:
Sub saveAddEmployee()
Application.ScreenUpdating = False
Dim rowCounter As Integer
Dim curSheet As String
curSheet = ActiveSheet.name
rowCounter = 1
Do Until Sheets("Employees").Cells(rowCounter, 1).Value = Empty
rowCounter = rowCounter + 1
Loop
Sheets("Employees").Cells(rowCounter, 1).Value = frmAddEmployee.txtFirstName.Value & " " & frmAddEmployee.txtLastName.Value
Sheets("Employees").Cells(rowCounter, 2).Value = frmAddEmployee.txtAddress.Value
Sheets("Employees").Cells(rowCounter, 3).Value = frmAddEmployee.txtCity.Value
Sheets("Employees").Cells(rowCounter, 4).Value = frmAddEmployee.cmboxState.Value
Sheets("Employees").Cells(rowCounter, 5).Value = frmAddEmployee.txtZipCode.Value
Sheets("Employees").Cells(rowCounter, 6).Value = frmAddEmployee.txtHourRate.Value
Sheets.add After:=Sheets(Sheets.Count)
ActiveSheet.name = frmAddEmployee.txtFirstName.Value & " " & frmAddEmployee.txtLastName.Value
Range("a1").Value = "Pay Date"
Range("b1").Value = "Pay Hours"
Range("c1").Value = "Pay Amount"
Range("d1").Value = "Pay Period"
Range("A1:D1").Select
Selection.Font.bold = True
Cells.EntireColumn.AutoFit
Range("B2:B2000").Select
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
End With
Selection.NumberFormat = "0.00"
Range("a1").Select
clearFields 'sub that clears all the data in the userform
frmAddEmployee.txtFirstName.SetFocus
Sheets(curSheet).Select
MsgBox "Employee Added Successfully"
Application.ScreenUpdating = True
frmAddEmployee.txtFirstName.SetFocus
End Sub