View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
cesw cesw is offline
external usenet poster
 
Posts: 1
Default SetFocus problem


Hi - we are using Excel 2000 VBA

When an error occurs, I want to put up a message box and then put th
cursor in the incorrect textbox on my form.
Here is the code - comments to the left indicate what happened when
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, use
clicks ok
ckbTTM.SetFocus ' pgm continues, an
focus is set here
ckbCustID.SetFocus ' pgm cont, and focu
is set here
tbEnd.SetFocus ' pgm cont, focu
stays ckbCustID
End If
End If
End Sub ' return t
form and focus is on OK button

Private Sub tbStart_AfterUpdate()
If tbStart = "" Then ' user enter
incorrect date and tabs
MsgBox ("Start Date Required") ' msgbox works fine
Me.tbStart.SetFocus ' focus is on next Ta
stop
Exit Sub
End If
If Not isValidDate(tbStart) Then
MsgBox ("Start Date Invalid")
tbStart.SetFocus ' same thing
End If
End Sub

Any thoughts?
Th

--
ces
-----------------------------------------------------------------------
cesw's Profile: http://www.excelforum.com/member.php...fo&userid=2711
View this thread: http://www.excelforum.com/showthread.php?threadid=46631