This bit won't work as you think, if it were to work at all.
Setting the .RecordSource requires linked tables.
You would want something more along the lines of:
Code:
' ...
' Check if any records are found
If Not rs.EOF Then
' Set the recordset of the report to the recordset object
Set Me.Recordset = rs
End If
' ...
However, I'm not 100% sure that Access reports can use ADODB.Recordset's as their recordset.
If not, you would have to use a DAO.Recordset. I imagine the code would look something like:
Code:
' ...
' Set the SQL query
strSQL = "SELECT * FROM MC_PrescriptionQ ;"
' Create a temporary query
With CurrentDb.CreateQueryDef(vbNullString)
.Connect = DBcon
.SQL = strSQL
.ReturnsRecords = True
' Open the recordset
Set rs = .OpenRecordset
End With
' Check if any records are found
If Not rs.EOF Then
' Set the record source of the report to the SQL query
Set Me.Recordset = rs
End If
' ...
You can't set the Report.RecordSet property unless it is an ADP Database.
Workaround:
Link the view(MC_PrescriptionQ) then your code can set the Report.RecordSource property (or use a DAO Pass-Through query or a temp table with data from ADO query).
You can't set the Report.RecordSet property unless it is an ADP Database.
Workaround:
Link the view(MC_PrescriptionQ) then your code can set the Report.RecordSource property (or use a DAO Pass-Through query or a temp table with data from ADO query).
well i m using a connection string to connect whenever need be and close DB connection as soon as i m done. Previously i used linked tables but users have to wait long for queries and forms and report to open or load. But your point looks valid and i m now considering to use linked tables for querries and reports and keep the forms unbound and use connection string for CRUD
strSQL = "SELECT * FROM MC_PrescriptionQ ;"
rs.Open strSQL, DBCon, 1, 3
' Check if any records are found
If Not rs.EOF Then
' Set the record source of the report to the SQL query
Me.RecordSource = strSQL
End If
This is particularly bad. You load unfiltered data TWICE. The ADODB recordset has nothing to do with the form recordset.