Hi 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
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
Murray,
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.
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.