SetFocus is placing focus on incorrect textbox

30 Views Asked by At

When I check the value of the user's input and the user did not input a valid response, I set focus back to that textbox. However, that is not happening. Instead, it is advancing to the next textbox.

CODE:

Private Sub tbxStartTime_AfterUpdate() 
  Dim ckTime As Date 
  On Error Resume Next 
  ckTime = DateValue(tbxStartTime.Value) 
  MsgBox ckTime 

  tbxStartTime.Text = Format(dTime, "h:mm am/pm") 

  If tbxStartTime.Value = "" Or Not IsDate(tbxStartTime.Text) Or Not tbxStartTime = Format(tbxStartTime.Value, "h:mm am/pm") Then 
     MsgBox "Please enter the Time in the correct format" 
     tbxStartTime = "" 
     tbxStartTime.SetFocus 
     Exit Sub 
  End If 

End Sub

Textbox indicated in red is the one I am checking with above code. It is tbxStartTime. However, the focus is put on the textbox below it, tbxClassHours

Screenshot of textbox I am checking.

As far as I can tell, the syntax is correct for what I want to happen.

0

There are 0 best solutions below