Formatting controls on subform - vba question

L

Larry Kahm

I normally like the sunken mode of text controls to indicate data entry and
the flat mode to indicate display.
I have used the following code to format the controls on a form for "browse"
mode - only it does not (yet) handle the controls on a subform.

Function FormatControls()
' Set all text, checkbox, and list controls to Flat during browse - the
default is Sunken for data entry
Dim ctl As Control ' form controls

For Each ctl In Me.Section(acDetail).Controls ' only modify
the Detail section
With ctl
Select Case .ControlType
Case acTextBox, acListBox, acComboBox, acCheckBox
.SpecialEffect = 0 ' Flat
Case acSubform
' modify sub-form boxes...
Case Else
' Do nothing
End Select
End With
Next ctl
Set ctl = Nothing

End Function

I'm stumped as to how to refer to the collection on the subform's detail
section to manipulate those controls.

Any help would be greately appreciated.

Thanks in advance.

Larry
 
L

Larry Linson

If your code is to run in, or called from, an event of the main form, you
can refer to the Form embedded in the Subform Control, with

Me.nameofsubformcontrol.Form

So it might be as simple as changing your statement
"For Each ctl In Me.Section(acDetail).Controls"
To
"For Each ctl In Me.nameofsubformcontrol.FormSection(acDetail).Controls
where you replace "nameofsubformcontrol" with the actual, er, name of your
subform control.

If you run or call the code from an event of the Form embedded in the
Subform Control, it may work just "as is".

Larry Linson
Microsoft Office Access MVP
 

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