amorosik
Active member
- Local time
- Today, 12:10
- Joined
- Apr 18, 2020
- Messages
- 665
You cannot use an ADO recordset as the source of a report.
![]()
Ok, this is THE answer to my question
You cannot use an ADO recordset as the source of a report.
![]()
That note is super confusing. That is on the "Report.Recordset" page but the conversation switches back and forth between a Form's recordset and a report recordset. The two capabilities are not the same AFAIK.You cannot bind reports to ADO recordsets. You must either use DAO or else dump the ADO recordset to a temporary table, and then bind the report to that temporary table.
| Bind ADO Recordset | Bind DAO Recordset | |
| Access Form | Yes | Yes |
| Access Report | No | No |
| Access ADP Report | No but who cares | Yes but who cares |
@amorosik I have created VB programs using Winsock and similar programs for IBM mainframes using COBOL but never thought to do it with Access since Access isn't meant to be left open 24/7. So, thanks for the explanation of how to use it in Access.
Since you have to move the data somewhere, copy it to TempVars rather than creating a recordset. Then set the report controls to the Tempvars.
=TempVarABC
As if I needed another reason not to use reports.
A custom function that creates Word or Excel documents based on a template. Depending on the context of what I want to return. I would not use mail merge either, it sucks.If you want to print and don't use reports, what would you use?
A custom function that creates Word or Excel documents based on a template. Depending on the context of what I want to return. I would not use mail merge either, it sucks.
I would check what else can be used, maybe HTML or bare txt file.Interesting possibility
And on pc where Word / Excel is not present?
impossible? i gave you the code to Create the Local table based on your original code on the formOk, then it seem that is not possible
impossible? i gave you the code to Create the Local table based on your original code on the form
and still you find it impossible.
the answer, You Cant pass a Recordset to a Report."how to pass in memory ado recordset to report"
Set MyrsAdoDb = New ADODB.Recordset
MyrsAdoDb.Fields.Append "read_number", adInteger
MyrsAdoDb.Fields.Append "table_name", adVarChar, 250
MyrsAdoDb.Open , , adOpenDynamic, adLockOptimistic
MyrsAdoDb.AddNew Array("read_number", "table_name"), Array(Count, tdf.Name)
MyrsAdoDb.Sort = "table_name asc"
Set Me.Recordset = MyrsAdoDb
'arnelgp
'write to textfile
Dim path As String
Dim filenum As Integer
path = CurrentProject.path & "\read.txt"
filenum = FreeFile
Open path For Output As filenum
With MyrsAdoDb
If Not (.BOF And .EOF) Then
.MoveFirst
End If
Do Until .EOF
Print #filenum, !read_number & ", " & !table_name
.MoveNext
Loop
End With
Close #filenum
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = _
"SELECT [Read#txt].F1 AS read_number, [Read#txt].F2 AS table_name" & _
" FROM [Read#txt] IN '" & CurrentProject.path & "'[Text;FMT=Delimited;HDR=NO;IMEX=2;]"
End Sub
So your recordset contains only a single record?The form is fed from a recordset that I loaded earlier with the following code
Code:--------------------------------------- Set MyRsAdoDb = New ADODB.Recordset MyRsAdoDb.Fields.Append "read_number", adInteger MyRsAdoDb.Fields.Append "table_name", adVarChar,250 MyRsAdoDb.Open , , adOpenDynamic, adLockOptimistic MyRsAdoDb.AddNew Array("read_number", "table_name"), Array(count, tdf.name) MyRsAdoDb.Sort = "asc table_name" Set Me.Recordset = MyRsAdoDb ---------------------------------------
Me.RecordSource = "SELECT TOP 1 " & _
"'" & count & "' AS read_number, " & _
"'" & tdf.name & "' AS table_name " & _
"FROM MSysObjects;"
Me.RecordSource = Forms("YourFormName").RecordSource
@amorosik I gave you a solution back in #27 which you totally ignored.
So your recordset contains only a single record?
Or is there a loop that you haven't shown in the code that adds multiple records?
The above could be replaced with:
Code:Me.RecordSource = "SELECT TOP 1 " & _ "'" & count & "' AS read_number, " & _ "'" & tdf.name & "' AS table_name " & _ "FROM MSysObjects;"
Then you can either assign the same SQL to your report's RecordSource, or do something like (within your report's Open event):
Code:Me.RecordSource = Forms("YourFormName").RecordSource
However, it seems strange to use a continuous form for just a single record.
The question was answered: it's not possible.The question is not 'what the recordset contains', but whether it is possibile to pass it to the report for feeding and printing
The question was answered: it's not possible.
So now the question becomes: do you want to get the data in to a report and, if so, what's the most effective way of doing so?
... or perhaps there's a better way to gather the data than using an ADODB recordset in the first place?