title: How to capture the time from textbox and paste it in excel sheet
body: <p>Employee login system using excel with macro.
  An employee will enter employee ID and then display their name in txtName.  If they hit login button, I want to be able to capture the login time and paste it in excel sheet and then do vice versa when they logout.</p>
  
  <p>Here's the screenshot: <a href="https://i.stack.imgur.com/O4cs1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O4cs1.png" alt="Screenshot"></a></p>
  
  <p>2nd screenshot for logout:
  <a href="https://i.stack.imgur.com/SlvWw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SlvWw.png" alt="Logout_issue"></a></p>
  
  <p>Here's the code so far:</p>
  
  <pre><code>Dim CM As Boolean
  
  Private Sub txtEmpID_Change()
  
  Dim mySheet As Worksheet
  Dim myRange As Range
  
  Set mySheet = Sheets("Emp_ID")
  Set myRange = mySheet.Range("B:B").Find(txtEmpID.Value, , , xlWhole)
  
  If Not myRange Is Nothing Then
  txtName.Value = myRange.Offset(0, -1)
  Else
  txtName.Value = "Match not found"
  End If
  
  End Sub
  
  Private Sub UserForm_activate()
  
  Do
  If CM = True Then Exit Sub
  txtTime = Format(Now, "hh:mm:ss")
  DoEvents
  Loop
  
  End Sub
  
  Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  
  CM = True
  
  End Sub
  </code></pre>