Hi,
In my database I am trying to produce a "Statistics" function. As part of this, the user will enter a "Start Date" and "End Date" in a form and then click a button which will open the requested report with the date drawn from a query. The code on clicking the "All Jobs" button is:
Which works perfectly.
I am trying to stop the user from leaving the date fields blank or entering dates outside of the range of the database so I have tried the code:
If the user enters dates within the range of the database the report is presented correctly.
If the user does not enter a date or enters one outside of the range it produces the correct message box however if the user then corrects the mistake I receive a Runtime Error 3071 message. Clicking "Debug" highlights the final line of code:
I know that the code is correct because it works fine as stand alone code and it works if the user enters the correct dates so I am not sure where I am going wrong.
Just for clarification, I am British and the date format works perfectly for the way dates are formatted in the database.
Thanks in advance for your help.
In my database I am trying to produce a "Statistics" function. As part of this, the user will enter a "Start Date" and "End Date" in a form and then click a button which will open the requested report with the date drawn from a query. The code on clicking the "All Jobs" button is:
Code:
DoCmd.OpenReport "RepStatisticsAllJobs", acViewPreview
I am trying to stop the user from leaving the date fields blank or entering dates outside of the range of the database so I have tried the code:
Code:
Private Sub AllSalesEnquiries_Click()
If Me.DateFrom = "" Then
Beep
If MsgBox("You have not entered a start date", vbCritical, "Start Date Not Entered") Then
Exit Sub
End If
ElseIf Me.DateFrom <#24/03/2014# Then
Beep
If MsgBox("The database does not contain records before 24th March 2014", vbCritical, "Start Date Too Early") Then
Exit Sub
End If
ElseIf Me.DateTo = "" Then
Beep
If MsgBox("You have not entered an end date", vbCritical, "End Date Not Entered") Then
Exit Sub
End If
ElseIf Me.DateTo > Date() Then
Beep
If MsgBox("You cannot search beyond today's date", vbCritical, "End Date After Today") Then
Exit Sub
End If
End If
DoCmd.OpenReport "RepStatisticsAllJobs", acViewPreview
End Sub
If the user does not enter a date or enters one outside of the range it produces the correct message box however if the user then corrects the mistake I receive a Runtime Error 3071 message. Clicking "Debug" highlights the final line of code:
Code:
DoCmd.OpenReport "RepStatisticsAllJobs", acViewPreview
Just for clarification, I am British and the date format works perfectly for the way dates are formatted in the database.
Thanks in advance for your help.