Question:
I have a situation where I would like to prepare a Recordset object
within Visual Basic (6.0), and then use the MS Access COM API's to
Show a report built off of the data in my Recordset (e.g. NOT letting
MS Access get its own data through its normal Tables, SQL statements,
etc).
I tried the following code:
Set rs = CreateObject("ADODB.Recordset")
' fill in my recordset with some valid data
Set mdb = CreateObject("Access.Application")
mdb.OpenCurrentDatabase("C:\Path\To\My.mdb", False)
mdb.Visible = True
mdb.DoCmd.OpenReport("RptName", acViewDesign)
Set mdb.Reports("RptName").Recordset = rs
mdb.DoCmd.OpenReport("RptName", acViewPreview)
and am seeing the following error on the next-to-last line:
"You can't assign a value to this object."
I tried using an .ADP file as well, but to no avail.
I ran across one suggestion of opening a recordset (within Access
Macro code though, which I'd prefer to avoid), and then setting
Report.recordSource = rs.Name inside the Report_Open event. I'd try
this approach, but I can't figure any way to provide my RS to a valid
global variable within MSAccess (that the Report_Open event proc could
see).
Thanks in advance for any assistance, or pointers to a working sample,
etc...
- Kevin