I have a report that has an on open event as follows:
Private Sub Report_Open(Cancel As Integer)
Dim strCriteria As String
strCriteria = InputBox("Please enter the full month for data you wish to see, e.g. type " & Chr(34) & "May." & Chr(34), "Enter month to view data"
If strCriteria = "January" Then
ElseIf strCriteria = "February" Then
ElseIf strCriteria = "March" Then
ElseIf strCriteria = "April" Then
ElseIf strCriteria = "May" Then
ElseIf strCriteria = "June" Then
ElseIf strCriteria = "July" Then
ElseIf strCriteria = "August" Then
ElseIf strCriteria = "September" Then
ElseIf strCriteria = "October" Then
ElseIf strCriteria = "November" Then
ElseIf strCriteria = "December" Then
Else
MsgBox "Incorrect month format has been entered", , "Error!"
DoCmd.Close
End If
End Sub
Basically an input box is requesting that a month is typed. If the month is not typed correctly, I want to close the report (I could put this code on a form rather than the report on open event, but I need to learn how to do it this way!)
I cannot use docmd.close as I have in my code above, as an error is generated: "This action cannot be carried out while processing a form or report".
Any resolutions gratefully accepted!
TIA
Private Sub Report_Open(Cancel As Integer)
Dim strCriteria As String
strCriteria = InputBox("Please enter the full month for data you wish to see, e.g. type " & Chr(34) & "May." & Chr(34), "Enter month to view data"
If strCriteria = "January" Then
ElseIf strCriteria = "February" Then
ElseIf strCriteria = "March" Then
ElseIf strCriteria = "April" Then
ElseIf strCriteria = "May" Then
ElseIf strCriteria = "June" Then
ElseIf strCriteria = "July" Then
ElseIf strCriteria = "August" Then
ElseIf strCriteria = "September" Then
ElseIf strCriteria = "October" Then
ElseIf strCriteria = "November" Then
ElseIf strCriteria = "December" Then
Else
MsgBox "Incorrect month format has been entered", , "Error!"
DoCmd.Close
End If
End Sub
Basically an input box is requesting that a month is typed. If the month is not typed correctly, I want to close the report (I could put this code on a form rather than the report on open event, but I need to learn how to do it this way!)
I cannot use docmd.close as I have in my code above, as an error is generated: "This action cannot be carried out while processing a form or report".
Any resolutions gratefully accepted!
TIA