Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetFocus won't return to Control 2

Status
Not open for further replies.

rockiwood

MIS
Apr 17, 2002
50
GB
I am attempting to force a user to put in a date in a control using the following code.

Private Sub txtRDate_Exit(Cancel As Integer)

If IsNull(Me.txtRDate) Then
MsgBox " Must have a Date to continue "
' Me.txtRDate.Enabled = True
Me.txtRDate.SetFocus
End If

End Sub


When I get the Message Box and select okay, it advances to the next field. How can i get it to go back to txtRDate? The setfocus seems to have no affect. I've tried it with the .enabled and without.

Thanks in advance!! :)

Jerry
 
When they have gotten as far a the Exit event it's too late to just halt things. Use the BeforeUpdate Event for the textbox so they never get away.

Private Sub txtRDate_Before_Update(Cancel As Integer)

If IsNull(Me.txtRDate) Then
MsgBox " Must have a Date to continue "
Cancel = True

End If

End Sub

Or better yet, use the Required property of the Table and force them to put a value in that way.

Paul




 
Actually, you can Cancel the exit event to set the focus back on the control:
Code:
Private Sub txtRDate_Exit(Cancel As Integer)

    If IsNull(Me.txtRDate) Then
        MsgBox " Must have a Date to continue "
        Cancel = True
    End If
    
End Sub
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Thanks for the help.. This site and the people are an invaluable tool for someone like me who forgets the basics and still needs to know all the rest!! :)

Jerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top