Changing back color of subforms when main form is in Data Entry mo

D

Darrell

My purpose is to give the user an unmistakable sign when they have opened a
form in Data Entry mode by changing the back color of the form and all
subforms. Rather than hard coding the name of each subform, I would like to
loop through the controls of the main form and if they are subforms, change
their back color (having determined that the form is in Data Entry mode, of
course).

This is the code I have tried so far:
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is SubForm Then

'Forms!frmTape!subfrmTapeProcedure.Form.Section(acDetail).BackColor = 9211609
'Me.Controls(ctl.Name).Form.Section(acDetail).BackColor =
9211609
End If
Next ctl

Can someone enlighten me as to what the syntax should be, or how else I
should attack this?
 
M

Marshall Barton

Darrell said:
My purpose is to give the user an unmistakable sign when they have opened a
form in Data Entry mode by changing the back color of the form and all
subforms. Rather than hard coding the name of each subform, I would like to
loop through the controls of the main form and if they are subforms, change
their back color (having determined that the form is in Data Entry mode, of
course).

This is the code I have tried so far:
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is SubForm Then

'Forms!frmTape!subfrmTapeProcedure.Form.Section(acDetail).BackColor = 9211609
'Me.Controls(ctl.Name).Form.Section(acDetail).BackColor =
9211609
End If
Next ctl

Can someone enlighten me as to what the syntax should be, or how else I
should attack this?


Try this:

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acSubForm Then
ctl.Form.Section(acDetail).BackColor = 9211609
End If
Next ctl
 
D

Darrell

Marshall, you're a genius! Thank you very much! It saved me a lot of time
going down other false paths since I thought I had just about exhausted the
syntax variations (I had tried several other variations since posting last
evening).

Obviously, a second benefit is knowing that other possible issues, like
trying other events to associate this with are not necessary. I now know that
properties of subforms CAN be addressed in the load event of the main form.

Thanks again!
 

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