Hello,
I have a Report for which the underlying Query takes a parameter from a Form Control.
I want to implement a series of simple checks along the following lines, before the Form is 'open':
1) the Form (with the control that supplies the parameter) is open
2) the Control which supplies the parameter is populated
The Report should close if either condition is false.
The issue that I'm having is that the parameter prompt is appearing before these checks have taken place - that and the Report does not close. The Code I have used is below:
Any advice much appreciated!
Code:
Private Sub Report_Load()
On Error GoTo ErrorHandler
' Check that a IN_CCODE has been supplied
If CurrentProject.AllForms("MAIN").IsLoaded = False Then
MsgBox ("This Report is not designed to be opened directly." & vbCrLf & "The Report will now close.")
DoCmd.Close acReport, Me.Name
Else
If IsNull(Me![IN_CCODE]) Then
MsgBox ("This Report requires the specified Parameter.")
End If
End If
Exit Sub
ErrorHandler:
MsgBox ("Error")
End Sub