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).
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).