Pulling the record souce object out of Report from a FORM (1 Viewer)

robertlewisnet

New member
Local time
Today, 06:04
Joined
Mar 21, 2005
Messages
8
I have an option group that has many reports being picked using a CASE statement and being fed into a DoCmd.OpenReport command. I am wanting to not actually run the report, but the query (Record Source) and then export the results into a csv file. the issue is I want the query to be run to be as dynamic as the report that is picked.

My question is basically how do you (knowing the report name) go to that report and pull the "Record Source" into a variable so I can feed that variable into a query. I don't know how to export it yet but if this detail get's answered that should not be a problem to find on the forum.

-thanks again.
 

Jon K

Registered User.
Local time
Today, 12:04
Joined
May 22, 2002
Messages
2,209
You can open the report, read the RecordSource and immediately close the report e.g.

Code:
Private Sub Command0_Click()

   Dim strRecordSource As String
   
   On Error GoTo ErrHandler
   Application.Echo False
   
   DoCmd.OpenReport "reportName", acViewPreview
   
   strRecordSource = Reports("reportName").RecordSource
   
   DoCmd.Close acReport, "reportName"
   Application.Echo True
   
   Exit Sub
   
ErrHandler:
   MsgBox Err.Description
   Application.Echo True

End Sub
.
 

robertlewisnet

New member
Local time
Today, 06:04
Joined
Mar 21, 2005
Messages
8
99% there...

You are good. the only thing i had to work through was to change the report to Design mode from Prieviw so the RecordSource would be available.

thank you for your help. It works very nicely. Off to searching for the export options!

-Robert
 

Users who are viewing this thread

Top Bottom