How do I access the controls on one form from the code module ofanother?

C

Chrisso

Hi All

I have one form with a command button. When this command button is
clicked I open another form - I then want to change some of the
controls on this form from the code of the starting form:

DoCmd.OpenForm "cFrmDocFullDetails" '
launch form
' now set the required fields backgrounf colour to pale yellow:
' argh! dont know how to access this form

How do I access the controls on one form from the code module of
another? I cannot work out how to get a handle on the form that I jsut
opened. Can I loop through all the forms or something? Can I straight
instantiate an object that is the form?

I have another similar question - when I open the form why cant I do
something like this:
ThisDatabase.cFrmDocFullDetails.Show
or something similar. Is coding of this type possible?

Any help would be great.

Thanks
Chrisso
 
R

ruralguy via AccessMonster.com

You can go through the Forms collection:
Forms.OtherFormName.ControlName

...using your form and control names of course. Only forms that are open are
in the Forms collection.
 
D

Dale Fye

All of the methods shown below will allow you to reference a control on
another form. The advantage of the first one is that it will provide you
with intellisense, so you can see the name of the controls as well as that
controls properties while you are typing, whereas in the other two methods,
you have to know the controls name and the applicable properties.

Form_frm_Employees.txt_FieldName.backcolor = 255
Forms("frm_Employees").Controls("txt_FieldName").BackColor = 255
Forms.frm_Employees.txt_FieldName.BackColor = 255

HTH
Dale
 
C

Chrisso

All of the methods shown below will allow you to reference a control on
another form. The advantage of the first one is that it will provide you
with intellisense, so you can see the name of the controls as well as that
controls properties while you are typing, whereas in the other two methods,
you have to know the controls name and the applicable properties.

Form_frm_Employees.txt_FieldName.backcolor = 255
Forms("frm_Employees").Controls("txt_FieldName").BackColor = 255
Forms.frm_Employees.txt_FieldName.BackColor = 255

HTH
Dale

--
Don''t forget to rate the post if it was helpful!

Email address is not valid.
Please reply to newsgroup only.

Thanks RG and Dale. Cheers Chrisso
 

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