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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test txtBox for valid dates can't get msgbox to close

Status
Not open for further replies.

mischief911

Technical User
Jan 14, 2002
21
US
This is a real newbie question

I have a form with 2 textboxes 1)start date 2) end Date for a report date range. A valid start and end date needs to be entered before the underlying report generation macro can function properly. I am trying to test for a valid date in each text box and throw up a msgbox in response to whichever textbox value is missing. I am looping through this test so that it will run until the proper data has been entered. The only problem is i can't get the msgbox dialog to close so that the focus can be returned to the appropriate start date/end date textbox for user input. It enters into an endless loop and won't let me close the msgbox dialog to input the dates.

 
Put this code on the OnClick event of a button on your form:

============
If Not IsNull(Me.StartDate) And IsDate(Me.StartDate) Then
If Not IsNull(Me.EndDate) And IsDate(Me.EndDate) Then
DoCmd.RunMacro "YourMacroNameHere"
Else
MsgBox "You must enter a valid end date to continue"
Me.EndDate.SetFocus
End If
Else
MsgBox "You must enter a valid start date to continue"
Me.StartDate.SetFocus
End If
============
Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top