Hi there
I am braving it and trying out VBA!
I have a form which enters start and end dates and then opens a report
I am trying to set up error handling which asks for the start and end date and then tells the user there isn't any matching records.
At the moment if I deliberately enter start/end dates out of range my report still opens up without the warning - to a report with no data.
here is my code
Private Sub Command18_Click()
If (Eval("[Forms]![frmReport]![startdate] Is Null")) Or (Eval("[Forms]![frmReport]![enddate] Is Null")) Then
Beep
MsgBox "Both start date and end date are required", vbOKOnly, ""
Else
On Error GoTo Err_Command18_Click
Dim stDocName As String
stDocName = "Treatment options discussed report"
DoCmd.OpenReport stDocName, acPreview
Exit_Command18_Click:
Exit Sub
Err_Command18_Click:
Beep
MsgBox "No records match this query", vbOKOnly, ""
Resume Exit_Command18_Click
End If
End Sub
any ideas whats wrong?
I am braving it and trying out VBA!
I have a form which enters start and end dates and then opens a report
I am trying to set up error handling which asks for the start and end date and then tells the user there isn't any matching records.
At the moment if I deliberately enter start/end dates out of range my report still opens up without the warning - to a report with no data.
here is my code
Private Sub Command18_Click()
If (Eval("[Forms]![frmReport]![startdate] Is Null")) Or (Eval("[Forms]![frmReport]![enddate] Is Null")) Then
Beep
MsgBox "Both start date and end date are required", vbOKOnly, ""
Else
On Error GoTo Err_Command18_Click
Dim stDocName As String
stDocName = "Treatment options discussed report"
DoCmd.OpenReport stDocName, acPreview
Exit_Command18_Click:
Exit Sub
Err_Command18_Click:
Beep
MsgBox "No records match this query", vbOKOnly, ""
Resume Exit_Command18_Click
End If
End Sub
any ideas whats wrong?