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!

How do I return to form if an input error?

Status
Not open for further replies.

EdAROC

Programmer
Aug 27, 2002
93
US
Got a form for user to enter begin and end dates and click a "Run Report" button. This initiates code to check for valid dates and display an appropriate message. If a date is invalid, what is the best way to exit the sub and return to the form? Here's the code for checking, displaying, then it needs to "exit" to the form:

intCkSum = 0

If IsNull(Me.txtDate1) Or Not IsDate(Me.txtDate1) Then
intCkSum = 1
End If

If IsNull(Me.txtDate2) Or Not IsDate(Me.txtDate2) Then
intCkSum = intCkSum + 2
End If

If intCkSum Then
Select Case intCkSum
Case 1
Me.txtErrMsg = "Invalid Beginning Date"
Me.txtDate1.SetFocus
Case 2
Me.txtErrMsg = "Invalid Ending Date"
Me.txtDate2.SetFocus
Case 3
Me.txtErrMsg = "Invalid Dates"
Me.txtDate1.SetFocus
End Select

'Return to the form
'???? <What is best way to exit?>
End If

==============================================================
txtDate1 is Begin Date, txtDate2 is End Date
Instead of a MsgBox (IMHO an obnoxious interruption to the user) a message is displayed, in bold red letters. There's other code to clear that message, Me.txtErrMsg, when entering the subroutine (covers when they had an error, re-entered the data, and clicked "Run Report" again).
 
Exit Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OK. Thanks. Easy enough.

That's what I have, just wasn't sure if it was "the clean" way, "covered all the bases". Like, should I set some other values or close / display something. (I understand the event driven concept, just don't know all the details that need to be minded).

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top