How can I obtain Form metadata programmatically

G

Garry

Hi!

I want to know if its possible to programmatically obtain
the form metadata (and for that matter report & module
metadata also!)

I've looked at the VBA DAO object library and I see it has
TableDef and QueryDef classes so it's trivial to get the
table and query metadata using these classes.

However, I don't see FormDef, ReportDef, or ModuleDef
classes that will do the same for forms, reorts, and
modules respectively.

Can somebody please tell me if this is possible is
possible, and if so, how I can do it (preferably in DAO or
ADO VB).

thanks in advance
- Garry
 
N

Naresh Nichani MVP

Hi:

Type using the Containers property in the CurrentDb Object. You can access
forms and reports and just about anything here. Here 5 refers to reports.
The line below gives the name of the first report. Try it in the Debug
Window

?application.CurrentDb.Containers(5).Documents(0).Name

Regards,

Naresh Nichani
Microsoft Access MVP
 
G

Garry

Thanks Naresh!

I can get some of the high-level attributes using this
method e.g. Name, but how, for example, would I obtain
information regarding the controls in the Page Footer
section of a Report?

Will your provided solution be able to obtain this kind of
low-level stuff also?

thanks again
 
A

Adrian Jansen

You can get the full details of the form/report, by using the SaveAsText
command to write the entire object out as a text file. Parsing that is not
for the faint-hearted, but it can be done.

Otherwise cycling through the controls collection for each section of the
object gives you a fair bit of info.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
T

TC

All you get from Container Documents is their name, and maybe one or two
other simple attributes (I don't have Access here to check). You can not get
at their >content<, which is what the OP has asked for. He will have to open
each form or report in design view, then use the Forms or Reports
collection.

Something like (untested):

dim doc as document, frm as form, ctl as control, prp as property
for each doc in dbengine(0)(0).containers![forms].documents
debug.print vbcr; "FORM "; doc.name
docmd.openform doc.name, acdesign ' < check parameter order.
set frm = forms(doc.name)
for each prp in frm.properties
debug.print "prop: "; prp.name
next
for each ctl in frm.controls
debug.print "ctl: "; cl.name
next
' and so on.
docmd.close cform, frm.name ' < check parameter order.
next

Or use SaveAsText, as someone else suggested.

HTH,
TC
 

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