Controls in form




I am trying to get the details of controls within a form.

This code works when the form is loaded, but if it isnt, then it doenst.

Dim frm As Form

Set frm = Forms("frm_policies")

For Each ctl In frm

Debug.Print ctl.Name

Next ctl

Thanks in advance.


The form must be open for its properties to be exposed. If you don't want
users to see it, you can open it in design mode, hidden.

Douglas J. Steele

That's correct. The Forms collection only contains those forms that are
currently open.

What you can do is something like:

Dim dbCurr As DAO.Database
Dim conForms As DAO.Container
Dim docCurr As DAO.Document
Dim ctlCurr As Control
Dim frmCurr As Form

Set dbCurr = CurrentDb()
Set conForms = dbCurr.Containers!Forms
With conForms
For Each docCurr In .Documents
DoCmd.OpenForm docCurr.Name, acDesign, , , acFormReadOnly, acHidden
Set frmCurr = Forms(docCurr.Name)
Debug.Print frmCurr.Name & " contains:"
For Each ctlCurr In frmCurr.Controls
Debug.Print ctlCurr.Name
Next ctlCurr
DoCmd.Close acForm, frmCurr.Name, acSaveNo
Next docCurr
End With

Set dbCurr = Nothing

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

Similar Threads