Avatar of Murray Brown
Murray Brown
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Access VBA show report using any sql

What Access VBA code would I use to display data using any SQL code and would I need to set up a form for this or could one be generated? Thanks
Microsoft AccessVBA

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
John Tsioumpris

Do you mean something like "Dynamic Reports"....one time you get 10 fields, another 20 fields and so on... ?
If this is the case you need to either work in code to create Reports from code with the CreateControl method (but this means that you should work on .accdb database)  or instead have a lot of unbound fields that you populate dynamically using the OnFormat event of Report.
Daniel Pineault


Could you elaborate a little more on what you are hoping to build.
Jim Dettman (EE MVE)

 Basically you'd need to do it all manually with an "un-bound" report (no recordsource set).

 You'd open your recordsource in the report's OnOpen event based on the SQL you've generated.  Then in the OnFormat of the detail section, you would push data from the current record of the recordset into un-bound controls as needed.

In the OnPrint event, you'd then do:

If  Not rst.EOF then
   Me.Movenext = False
End If

As you would not want the report engine trying to move to the next record (which as far as it is concerned, there is none).

Only when you reached the end of your record set processing would you want it to try and continue.

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Fabrice Lambert

This might be doable, but I don't think it is worth it.

Any "linked" thing in Access is tightly coupled with its data source, making them dynamic is asking for a lots of troubles.
Gustav Brock

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Murray Brown

thanks very much
Gustav Brock

You are welcome!
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.