Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Might I suggest a different approach. If you use the Exit event you can
just set cancel to True - this will prevent the user exiting the textbox altogether - rather than having them leave and programmatically returning them. Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) If Textbox1 = "" then cancel = true end if End Sub HTH, Gareth cesw wrote: Hi - we are using Excel 2000 VBA When an error occurs, I want to put up a message box and then put the cursor in the incorrect textbox on my form. Here is the code - comments to the left indicate what happened when I stepped through the code with the debugger: Private Sub tbEnd_AfterUpdate() If tbEnd < "" Then If Not isValidDate(tbEnd) Then MsgBox ("End Date Invalid") ' displays fine, user clicks ok ckbTTM.SetFocus ' pgm continues, and focus is set here ckbCustID.SetFocus ' pgm cont, and focus is set here tbEnd.SetFocus ' pgm cont, focus stays ckbCustID End If End If End Sub ' return to form and focus is on OK button Private Sub tbStart_AfterUpdate() If tbStart = "" Then ' user enters incorrect date and tabs MsgBox ("Start Date Required") ' msgbox works fine Me.tbStart.SetFocus ' focus is on next Tab stop Exit Sub End If If Not isValidDate(tbStart) Then MsgBox ("Start Date Invalid") tbStart.SetFocus ' same thing End If End Sub Any thoughts? Thx |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
SetFocus problem | Excel Programming | |||
Userform setfocus problem | Excel Programming | |||
SetFocus Problem | Excel Programming | |||
TextBox SetFocus Problem | Excel Programming | |||
SetFocus problem | Excel Programming |