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

Question on error checking 2

Status
Not open for further replies.

BotCow

Programmer
Jul 10, 2003
58
US
I have search form that can search by date range. You just give it two dates and it pulls up a report about it. However, I'm not that experienced with VBA and I want to know how to display a msgbox when the user doesn't enter the second date (or one but not the other). Anyway, here's the segment of code.

If Not IsNull(Me.txtDate) Then
strWhere = strWhere & " (tblDocXLS.DATE) Between #" & Me.txtDate & "# AND #" & Me.txtDate2 & "# AND"
End If

I got it from jfgambit on this forum with his really helpful post on search forms. It just makes a string that is put into SQL to filter a table. If you have any suggestions or ideas, I would appreciate it, thanks.
 
Try This...

If IsNull(Me.txtDate1) Then
MsgBox "You have not entered a date in Box 1"
txtDate1.SetFocus
Exit Sub
If IsNull(Me.txtDate2) Then
MsgBox "You have not entered a date in Box 2"
txtDate2.SetFocus
Exit Sub
End If
End If



ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
Try:

If Not IsNull(Me.txtDate) AND Not IsNull(Me.txtDate2) Then
strWhere = strWhere & " (tblDocXLS.DATE) Between #" & Me.txtDate & "# AND #" & Me.txtDate2 & "# AND"
Else
MsgBox "Please enter a starting and ending date.", vbExclamation + vbOKOnly, "Missing Date(s)!"
Exit Sub
End If

Hope this helps!

Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top