O
Office User
I have 2 separate reports that each run based on date ranges. I created a
dialog box (form) and parameters in query to capture the data. I like the
form because it uses a calendar add-in and is user friendly. Unfortunately,
I can't get both reports to use this form and I'm sure it's based on the
code. I borrowed the code from Northwind (I think) and it makes sense
because it assures the user is opening report only if dialog box has been
opened first (at least that's how I'm interpretting it)
Here's the code in OpenEvent of my report:
Private Sub Report_Open(Cancel As Integer)
' Open Report Dates Dialog form.
' IsLoaded function (defined in Utility Functions module) determines
' if specified form is open.
Dim strDocName As String
strDocName = "frm ReportDate Dialog"
' Set public variable to True so Report Dialog knows that report
' is in its Open event.
blnOpening = True
' Open form.
DoCmd.OpenForm strDocName, , , , , acDialog
' If Report Dialog form isn't loaded, don't preview or print report.
' (User clicked Cancel button on form.)
If IsLoaded(strDocName) = False Then Cancel = True
'Set public variable to False, signifying that Open event is finished.
blnOpening = False
End Sub
Here's the blnOpening function:
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If
End Function
Here's the code for my OK button on my form:
Private Sub OK_Click()
On Error GoTo Err_OK_Click
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
' If Call Average report is not being opened for previewing or printing,
' cause an error. (blnOpening variable is true only when report's Open
event
' is being executed.)
If Not Reports![rpt CallsAvg by Interval].blnOpening Then Err.Raise 0
' Hide form.
Me.Visible = False
Exit_OK_Click:
Exit Sub
Err_OK_Click:
strMsg = "To use this form, you must preview or print needed report from
the Database window or Design view."
intStyle = vbOKOnly
strTitle = "Open from Report"
MsgBox strMsg, intStyle, strTitle
Resume Exit_OK_Click
End Sub
When I use the same code in Open Event of the other report and try to run
the report, I get the message for Err_OK_Click "To use this form, you must
preview or print needed report from the Database window or Design view."
I've tried to update the following line to include both report names but
can't seem to get the right combo (AND, OR, etc)
If Not Reports![rpt CallsAvg by Interval].blnOpening Then Err.Raise 0
Please advise if you see anything that can be done.
Thanks,
Marcia
dialog box (form) and parameters in query to capture the data. I like the
form because it uses a calendar add-in and is user friendly. Unfortunately,
I can't get both reports to use this form and I'm sure it's based on the
code. I borrowed the code from Northwind (I think) and it makes sense
because it assures the user is opening report only if dialog box has been
opened first (at least that's how I'm interpretting it)
Here's the code in OpenEvent of my report:
Private Sub Report_Open(Cancel As Integer)
' Open Report Dates Dialog form.
' IsLoaded function (defined in Utility Functions module) determines
' if specified form is open.
Dim strDocName As String
strDocName = "frm ReportDate Dialog"
' Set public variable to True so Report Dialog knows that report
' is in its Open event.
blnOpening = True
' Open form.
DoCmd.OpenForm strDocName, , , , , acDialog
' If Report Dialog form isn't loaded, don't preview or print report.
' (User clicked Cancel button on form.)
If IsLoaded(strDocName) = False Then Cancel = True
'Set public variable to False, signifying that Open event is finished.
blnOpening = False
End Sub
Here's the blnOpening function:
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If
End Function
Here's the code for my OK button on my form:
Private Sub OK_Click()
On Error GoTo Err_OK_Click
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
' If Call Average report is not being opened for previewing or printing,
' cause an error. (blnOpening variable is true only when report's Open
event
' is being executed.)
If Not Reports![rpt CallsAvg by Interval].blnOpening Then Err.Raise 0
' Hide form.
Me.Visible = False
Exit_OK_Click:
Exit Sub
Err_OK_Click:
strMsg = "To use this form, you must preview or print needed report from
the Database window or Design view."
intStyle = vbOKOnly
strTitle = "Open from Report"
MsgBox strMsg, intStyle, strTitle
Resume Exit_OK_Click
End Sub
When I use the same code in Open Event of the other report and try to run
the report, I get the message for Err_OK_Click "To use this form, you must
preview or print needed report from the Database window or Design view."
I've tried to update the following line to include both report names but
can't seem to get the right combo (AND, OR, etc)
If Not Reports![rpt CallsAvg by Interval].blnOpening Then Err.Raise 0
Please advise if you see anything that can be done.
Thanks,
Marcia