dcory
08-03-2010, 01:54 PM
Hi there,
I have a report. This report contains a number of sub report controls. I need to modify the query that is run to populate the sub report control.
When I select the sub report control on the report it looks like I have the SourceObject filed I can modify so I tried the following. Where
[Hospital - Main Report] is the name of the report
[Hospital - Top10lens] is the sub report within the report.
When I load the report I get the following error
Run-time error '2465'
Application-defined or object-defined error.
NOTE: There is no other VBA code in this report.
I'm guessing it is the way I'm trying to manipulate the SourceObject or Record Source field.
Private Sub Report_Load()
Reports![Hospital - Main Report]![Hospital - Top10lens].Report.SourceObject = "SELECT TOP 10 lens_type, RECORDCOUNT" & _
" FROM (SELECT * from (select count(*) AS RECORDCOUNT, patient_appointment_details.lens_type" & _
" FROM patient_appointment_details, patient_appointments where lens_type <> """ & _
" AND patient_appointments.appointment_id = patient_appointment_details.appointment_id" & _
" AND patient_appointments.appointment_date >= #04/1/2010#" & _
" AND patient_appointments.appointmentdate <= #06/30/2010#" & _
" GROUP BY patient_appointment_details.lens_type)" & _
" ORDER BY RECORDCOUNT DESC)"
End Sub
I have a report. This report contains a number of sub report controls. I need to modify the query that is run to populate the sub report control.
When I select the sub report control on the report it looks like I have the SourceObject filed I can modify so I tried the following. Where
[Hospital - Main Report] is the name of the report
[Hospital - Top10lens] is the sub report within the report.
When I load the report I get the following error
Run-time error '2465'
Application-defined or object-defined error.
NOTE: There is no other VBA code in this report.
I'm guessing it is the way I'm trying to manipulate the SourceObject or Record Source field.
Private Sub Report_Load()
Reports![Hospital - Main Report]![Hospital - Top10lens].Report.SourceObject = "SELECT TOP 10 lens_type, RECORDCOUNT" & _
" FROM (SELECT * from (select count(*) AS RECORDCOUNT, patient_appointment_details.lens_type" & _
" FROM patient_appointment_details, patient_appointments where lens_type <> """ & _
" AND patient_appointments.appointment_id = patient_appointment_details.appointment_id" & _
" AND patient_appointments.appointment_date >= #04/1/2010#" & _
" AND patient_appointments.appointmentdate <= #06/30/2010#" & _
" GROUP BY patient_appointment_details.lens_type)" & _
" ORDER BY RECORDCOUNT DESC)"
End Sub