January 13th, 2013, 04:12 AM
Join Date: Jan 2013
Time spent in forums: 22 m 14 sec
Reputation Power: 0
Opening a report and pass parameters to qry
I have a problem and write to see if you can give me some assistance. This is the first time in many years I have to ask for some assistance so I would appreciate nay help you can give me? Let me explain the scenario.
I have a user form called Frm_reports where the user can select a variety of filters
There is only one report available to the user at this time.
The form has preview button.
On clicking the preview button it should open the report filtered by the passed parameters..
I wish to pass the parameters to the query on the fly and then open the filtered report.
The code will not run?
Here is the code:
Public Sub cmdPreview_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As QueryDef
If rmselectreport.ItemsSelected.count = 0 Or rmselectperiod.ItemsSelected.count = 0 Then
MsgBox "You must select both a report and period(s) to run a report." & vbCr & vbLf _
& "Please check or reenter the requiired report / periods", vbOK, "Selection Error"
Set qdf = dbs.QueryDefs("Qry_rpt_CR") <<
qdf.Parameters(0) = “*”
qdf.Parameters(4) = Forms!frm_reports.rmselectperiod.Column(0, 0)
qdf.Parameters(3) = Forms!frm_reports.rmselectperiod.Column(0, 1)
qdf.Parameters(2) = Forms!frm_reports.rmselectperiod.Column(0, 2)
qdf.Parameters(1) = Forms!frm_reports.rmselectperiod.Column(0, 3)
'Close all objects
Set rst = Nothing
Set qdf = Nothing
Qry_rpt_cr is the query for the report which in turns runs from another query that has five parameters
The problems I have are on lines with <<
The first line says Object Variable not set? What does this mean?
Do I need so open the report in a different way??
If you could provide some help that would be greatly appreciated.