Using a variable to select a form name.

D

DaveFrag

I have a parent form which contains six child forms. The parent form is
named "JobMon" and the child forms are named "JMwin01" through "JMwin06".
Rather than referring to a control properity on each child form individually
such as "Forms!JobMon!JMwin01.Controls(BoxName).BackColor = SetColor", I'd
like to use a For...Next loop like I already do with the ".Controls(BoxName)"
control, for the child form names. How is this done for a form name?

Rather than...
Forms!JobMon!JMwin01.Controls(BoxName).BackColor = SetColor
Forms!JobMon!JMwin02.Controls(BoxName).BackColor = SetColor

I'd like to use...
For x = 1 to 6
Forms!JobMon!JMwin0(x).Controls(BoxName).BackColor = SetColor
Next x
 
J

John W. Vinson

I have a parent form which contains six child forms. The parent form is
named "JobMon" and the child forms are named "JMwin01" through "JMwin06".
Rather than referring to a control properity on each child form individually
such as "Forms!JobMon!JMwin01.Controls(BoxName).BackColor = SetColor", I'd
like to use a For...Next loop like I already do with the ".Controls(BoxName)"
control, for the child form names. How is this done for a form name?

Rather than...
Forms!JobMon!JMwin01.Controls(BoxName).BackColor = SetColor
Forms!JobMon!JMwin02.Controls(BoxName).BackColor = SetColor

Just use the Controls collection again - a Subform is a control on the
mainform, which contains a Form object:

For x = 1 to 6
Forms!JobMon!Controls("JMwin0" & x)!Form.Controls(BoxName).BackColor =
SetColor
Next x

(watch the word wrap of course)
 

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