Thor My
Thor My

Reputation: 299

Determine which Controls are in the Header/Footer of an Access form via VBA

I have a form with labels in the header and in the footer and description. I just want to list the labels from the header and avoid the others from the footer and description sections. I have the code that loops into the controls (For Each control in Form.Controls), what I need now is just to separate the header labels from the others.

Upvotes: 1

Views: 3851

Answers (2)

Summer-Time
Summer-Time

Reputation: 1874

The Section property from the form or report allow to access to a particular section. It is recommended you use the constants to make your code easier to read.

Form_Test.Section(acDetail).Controls.Count

Form_Test.Section(acheader).Controls.Count
Form_Test.Section(acFooter).Controls.Count

Form_Test.Section(acPageHeader).Controls.Count
Form_Test.Section(acPageHeader).Controls.Count

Upvotes: 1

David Jacobsen
David Jacobsen

Reputation: 474

Depending on which Header section you are talking about, you probably want either:

For Each ctl In Me.FormHeader.Controls

Or:

For Each ctl In Me.PageHeaderSection.Controls

However, through discussion in comments it was identified that you are looking to iterate through all of the controls in a form that is a subform in another form, in that case you would use the following:

Forms![frmMainForm]![frmSubForm].Form.FormHeader.Controls

Upvotes: 3

Related Questions