SetFocus?

P

plh

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
 
T

Tom Ogilvy

Just set the cancel argument of the exit event to True



' conditions not met
cancel = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top