#1   Report Post  
Posted to microsoft.public.excel.programming
plh plh is offline
external usenet poster
 
Posts: 48
Default SetFocus?

Hello Again Everyone,
I thought "SetFocus" would put the cursor back in the text box and select the
text, but it does not. What would I use to put the user back in the text box and
select the offending date?

Private Sub txtDate1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim bolT As Boolean
On Error GoTo hell
bolT = NotAWorkDay(txtDate1.Value)
Exit Sub
hell:
If Err.Number = 13 Then
MsgBox "Not a Valid Date"
txtDate1.SetFocus
Else
MsgBox "Error # " & Err.Number & " Descr: " & Err.Description
End If
End Sub

Function NotAWorkDay(dtTheDay As Date) As Boolean
Dim intRes As Integer
Select Case WeekDay(dtTheDay)
Case 1
intRes = MsgBox(dtTheDay & " falls on Sunday.")
txtDate1.SetFocus
Case 7
intRes = MsgBox(dtTheDay & " falls on Saturday.")
txtDate1.SetFocus
End Select
End Function

Thank You,
-plh


--
I keep hitting "Esc" -- but I'm still here!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SetFocus?

Just set the cancel argument of the exit event to True



' conditions not met
cancel = True

--
Regards,
Tom Ogilvy

"plh" wrote in message
...
Hello Again Everyone,
I thought "SetFocus" would put the cursor back in the text box and select

the
text, but it does not. What would I use to put the user back in the text

box and
select the offending date?

Private Sub txtDate1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim bolT As Boolean
On Error GoTo hell
bolT = NotAWorkDay(txtDate1.Value)
Exit Sub
hell:
If Err.Number = 13 Then
MsgBox "Not a Valid Date"
txtDate1.SetFocus
Else
MsgBox "Error # " & Err.Number & " Descr: " & Err.Description
End If
End Sub

Function NotAWorkDay(dtTheDay As Date) As Boolean
Dim intRes As Integer
Select Case WeekDay(dtTheDay)
Case 1
intRes = MsgBox(dtTheDay & " falls on Sunday.")
txtDate1.SetFocus
Case 7
intRes = MsgBox(dtTheDay & " falls on Saturday.")
txtDate1.SetFocus
End Select
End Function

Thank You,
-plh


--
I keep hitting "Esc" -- but I'm still here!



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 on a different sheet in VBA AaronC Excel Discussion (Misc queries) 1 June 9th 05 11:18 PM
setfocus Dean Reardon Excel Programming 2 December 15th 04 12:18 PM
setfocus after a msgbox simpleMod[_3_] Excel Programming 1 October 26th 04 07:25 PM
setfocus after a msgbox simpleMod Excel Programming 1 October 26th 04 04:35 PM
SetFocus Question Sam Excel Programming 2 August 20th 04 04:01 PM


All times are GMT +1. The time now is 12:42 PM.

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

About Us

"It's about Microsoft Excel"