title: How to put focus to textbox as needed
body: <p>I have a textbox on a userform. If the user fails to enter anything in this textbox, I need to trap that to force an entry. I can do this easily enough, but after notifying the user tht they need to make an entry, I want the focus to return to the textbox. Right now, it doesn't do that. Here is my code:</p>
  
  <pre><code>Private Sub txtAnswer_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  
  Select Case KeyCode
      Case 13:
          If Me.txtAnswer.Value = "" Then
              temp = MsgBox("You need to enter an answer!", vbCritical + vbOKOnly, "No Answer Found!")
              Me.txtAnswer.SetFocus
          Else
              recordAnswer
          End If
      End Select
  
  End Sub
  </code></pre>
  
  <p>This code works fine in that the message box pops up if the textbox is left blank. After clearing the message box, if I hit enter immediately again, the message box reappears, suggesting that the focus is on the textbox. However, if I try to enter a character (like the number '1' for example) nothing appears in the textbox.</p>
  
  <p>Can anybody suggest how I can get the focus back on this textbox in a way that will allow the user to enter data?  Thank you!</p>