Hello senile2,
I know this is solved but I just couldn't leave this alone. I combined all the functions into a Single UserForm. This should make life easier for everyone. I have included the complete code for the form below. The attached workbook has the new form along with a macro "Run" that will bring it. All your original forms and code are still iintact.
Dim DataBase As Range
Dim NameCell As Range
Sub GetLastTimeEntry()
Dim Rng As Range
Dim TimeIn As Double
Dim TimeOut As Double
Set DataBase = Sheet1.Range("A1").CurrentRegion
Set DataBase = DataBase.Offset(1, 0).Resize(RowSize:=DataBase.Rows.Count - 1)
TextBox1.Value = ""
TextBox2.Value = ""
TextBox2.Visible = False
' Find the Row of the Name Entered.
Set NameCell = DataBase.Find(ComboBox1.Value, , xlValues, xlWhole, xlByRows, xlPrevious, False, False, False)
If NameCell Is Nothing Then
' Use the next empty row if the name was not found.
Set NameCell = DataBase.Offset(DataBase.Rows.Count, 0).Cells(1, 2)
' Close the Drop Down List.
SendKeys "{ESC}"
DoEvents
' Set Time In to now.
TextBox1.Value = Format(Now(), "hh:mm AM/PM")
TextBox1.SetFocus
Exit Sub
Else
TextBox1.Value = Format(NameCell.Offset(0, 1), "hh:mm AM/PM")
TextBox1.SetFocus
End If
' Time Out
TextBox2.Visible = True
TextBox2.SetFocus
If IsEmpty(NameCell.Offset(0, 2)) Then
TextBox2.Value = Format(Now(), "hh:mm AM/PM")
Else
TextBox2.Value = Format(NameCell.Offset(0, 2), "hh:mm AM/PM")
End If
TextBox2.SelStart = 0
TextBox2.SelLength = Len(TextBox2)
' Comments
TextBox3.Enabled = True
TextBox3.Value = NameCell.Offset(0, 4)
End Sub
Private Sub ComboBox1_Click()
Call GetLastTimeEntry
End Sub
Private Sub CommandButton1_Click()
' ENTER DATA - TRANSFER DATA FROM USERFORM TO THE WORKSHEET
With NameCell
.Offset(0, -1).Value = Format(Now(), "short date")
.Offset(0, 0).Value = ComboBox1.Value
.Offset(0, 1).Value = TextBox1.Value
.Offset(0, 2).Value = TextBox2.Value
.Offset(0, 4).Value = TextBox3.Value
End With
End Sub
Private Sub CommandButton2_Click()
' CLOSE USERFORM
Unload Me
End Sub
Private Sub TextBox1_Enter()
' TIME IN
CommandButton1.Enabled = True
End Sub
Private Sub TextBox2_Enter()
' TIME OUT
CommandButton1.Enabled = True
End Sub
Private Sub UserForm_Activate()
' Activate Names Drop Down List
SendKeys "{F4}"
End Sub
Private Sub UserForm_Initialize()
Dim Rng As Range
Set Rng = Sheet2.Range("A1", Sheet2.Cells(Rows.Count, "A").End(xlUp))
With ComboBox1
.List = Rng.Value
.Value = " Type In or Choose "
.SelStart = 0
.SelLength = Len(.Value)
End With
Label4.Caption = Format(Now(), "long date")
CommandButton1.Enabled = False
TextBox2.Visible = False
TextBox3.Enabled = False
End Sub
Bookmarks