Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default SetFocus problem

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SetFocus problem JH Excel Programming 1 April 18th 05 03:55 PM
Userform setfocus problem Martin Hibberd[_2_] Excel Programming 1 November 10th 04 12:12 PM
SetFocus Problem Todd Huttenstine[_2_] Excel Programming 2 January 19th 04 10:50 PM
TextBox SetFocus Problem Tom Ogilvy Excel Programming 1 September 12th 03 01:27 PM
SetFocus problem RFraley Excel Programming 2 September 7th 03 01:18 PM


All times are GMT +1. The time now is 05:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"