Controls in form

  • Thread starter Thread starter nathan_savidge
  • Start date Start date
N

nathan_savidge

Hi,

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.
 
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
Debug.Print
DoCmd.Close acForm, frmCurr.Name, acSaveNo
Next docCurr
End With

Set dbCurr = Nothing
 
Back
Top