jleval
Registered User.
- Local time
- Today, 01:47
- Joined
- May 16, 2012
- Messages
- 53
I have a command button on a form that shows two text boxes when clicked. The two text boxes are the date range in which I want a connecting report to print. There is a start date and an end date.
The problem is that I dont want an error message to pop up whenever someone doesnt enter the date range. I have placed the following code within the onclick event but the statements go right past the if statement. (The two date range text boxes are unbound)
Here is what I have:
Private Sub CmdPrintDate_Click()
Dim strWHERE As String
If TxtStartDate = Null Then
MsgBox "You Must Enter a Start Date", vbOKOnly, "Input Required"
DoCmd.GoToControl Me.TxtStartDate
ElseIf TxtEndDate = Null Then
MsgBox "You Must Enter an End Date", vbOKOnly, "Input Required"
DoCmd.GoToControl Me.TxtStartDate
Else
strWHERE = "[TestDate] Between #" & Me.TxtStartDate & "# AND #" & Me.TxtEndDate & "#"
DoCmd.OpenReport "Batch2", acViewPreview, , strWHERE
DoCmd.Close acForm, "Batch", acSavePrompt
End If
When there are no values, I get a debug error. What I would really like to do is have a message box that says "You must enter a date", with the option of an Ok/cancel, where the okay returns to the form and the cancel takes you out of the procedure all together.
End Sub
The problem is that I dont want an error message to pop up whenever someone doesnt enter the date range. I have placed the following code within the onclick event but the statements go right past the if statement. (The two date range text boxes are unbound)
Here is what I have:
Private Sub CmdPrintDate_Click()
Dim strWHERE As String
If TxtStartDate = Null Then
MsgBox "You Must Enter a Start Date", vbOKOnly, "Input Required"
DoCmd.GoToControl Me.TxtStartDate
ElseIf TxtEndDate = Null Then
MsgBox "You Must Enter an End Date", vbOKOnly, "Input Required"
DoCmd.GoToControl Me.TxtStartDate
Else
strWHERE = "[TestDate] Between #" & Me.TxtStartDate & "# AND #" & Me.TxtEndDate & "#"
DoCmd.OpenReport "Batch2", acViewPreview, , strWHERE
DoCmd.Close acForm, "Batch", acSavePrompt
End If
When there are no values, I get a debug error. What I would really like to do is have a message box that says "You must enter a date", with the option of an Ok/cancel, where the okay returns to the form and the cancel takes you out of the procedure all together.
End Sub