control list

D

Dirk Goldgar

00KobeBrian said:
Is there a way to list out all controls in a report in Access 97?
Thanks.

You mean, like ...

DoCmd.OpenReport "YourReport", acViewDesign
For Each ctl In Reports("YourReport").Controls
Debug.Print ctl.Name
Next ctl
DoCmd.Close acReport, "YourReport", acSaveNo

? Or did you want to do something with the report while it's open in
preview mode?
 
D

Dirk Goldgar

00KobeBrian said:
Thanks, Is there a way to get the control data source as well?

Sure. Not all controls have a ControlSource property, so you have to
either check the type of control or just ignore errors while attempting
to list the ControlSource for all controls. A simple version would be
like this:

DoCmd.OpenReport "YourReport", acViewDesign

On Error Resume Next
For Each ctl In Reports("YourReport").Controls
Debug.Print ctl.Name;
Debug.Print , ctl.ControlSource;
Debug.Print ""
Next ctl

On Error GoTo 0 ' or your error-handler

DoCmd.Close acReport, "YourReport", acSaveNo
 
0

00KobeBrian

Thanks, this is exactly I need.

Dirk Goldgar said:
Sure. Not all controls have a ControlSource property, so you have to
either check the type of control or just ignore errors while attempting
to list the ControlSource for all controls. A simple version would be
like this:

DoCmd.OpenReport "YourReport", acViewDesign

On Error Resume Next
For Each ctl In Reports("YourReport").Controls
Debug.Print ctl.Name;
Debug.Print , ctl.ControlSource;
Debug.Print ""
Next ctl

On Error GoTo 0 ' or your error-handler

DoCmd.Close acReport, "YourReport", acSaveNo


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top