Changing subform backcolor from main form

G

Guest

Hi all
I have a main form with 5 subforms sitting on a tab control. I need to
change a subform backcolor depending on the status of a control on the main
form.

Using "Me!subform1.Form.controlname" (without the quotes) intellisence does
not show a backcolor property. Or variations Form-Subform-Controlname and
using either bang or dot.

So how do I change a subform backcolor using VB triggerd by say the
afterupdate event on a control on the main form?

TIA

johnb
 
A

Al Campagna

John,
A form does not have a Backcolor property. Each "section" in the form (Detail, Header,
Footer, etc..) does.
So, if you want to change the backcolor of the Detail section (assuming continuous
subform with transparent fields)...
Me.frmYourSubName.Form.Detail0.BackColor = QBColor(10)
If you need to change the backcolor of each text control in the subform...
Me.frmYourSubName.Form!YourFieldName.BackColor = QBColor(11)
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
G

Guest

Hi Al
Thanks for the info.
The syntax Me.frmYourSubName.Form.Detail0.BackColor = QBColor(10) thru up
an error message but with a bit tinkering around I got it to work by removing
the zero from the end of detail0. It now works a treat!!

Kind regards
johnb
 
B

BruceM

If you open the form in design view, click into the Detail section, and
click View > Properties you can see the name for the detail section. You
will see that it is named Detail, which is why Detail0 didn't work. Same
thing works for headers and footers.
 
A

Al Campagna

Any code you use from an NG post is an example only. You must interpolate the object
names to your own situation.
Glad you got it going... good luck.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
G

Guest

Hi Bruce
What I'm finding a bit confusing is that I refer to the Details section in
the Form_Current event on the main form and its changing the Detail section
on a subform which resides on a Tab Control.

Let me expand. I have the main form frm_CPS_HeaderDetails with 5 subforms
that sit on a Tab Control. The 1st subform is named frm_Parts with its main
form control Name = Parts.

A snippet of the VB syntax in the main form Form_Current event that changed
the subform backcolor is
Me.Parts.Form.Detail.Backcolor = RGB(19,91,241)
And it works a treat! Althought I do not fully understand why. But hey it
works problem solved thanks to Al.

regards johnb
 
B

BruceM

If Parts is the name of your form, I don't get it either. If Parts is the
name of the subform it makes sense.
 
A

Al Campagna

John,
I don't understand why the confusion...
A subform on a Tab control (or ANY control/s on a Tab) is considered (by address) to be
on the main form. There is no "address" indication for the TAB itself.
You would refer to it just as if it were not on a Tab at all, but just like a normal
subform on the Main.
Given Tab page Page1 and field MyField....
Wrong Forms!frmMainForm!Page1!MyField = "ABC"
Right Forms!frmMainForm!MyField = "ABC"
or simply...
MyField = "ABC"

I think that's what you're questioning...

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
G

Guest

Hi Al

I was thinking that the Tabs control sat between the Main Form and the Sub
Form from a Object hierarchy view point.(Wrong!) Life is so simple now that
I understand where the Tab Control resides.

Thank you Al for your tanacity and Bruce for your comments.

regards
johnb
 

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