A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

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



 
 
Thread Tools Display Modes
  #1  
Old November 27th, 2007, 05:21 PM posted to microsoft.public.access.forms
Chrisso
external usenet poster
 
Posts: 92
Default How do I access the controls on one form from the code module ofanother?

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


  #2  
Old November 27th, 2007, 05:38 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default How do I access the controls on one form from the code module ofanother?

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.

Chrisso wrote:
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


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

  #3  
Old November 27th, 2007, 06:32 PM posted to microsoft.public.access.forms
Dale Fye
external usenet poster
 
Posts: 2,651
Default How do I access the controls on one form from the code module of a

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").B ackColor = 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.


"Chrisso" wrote:

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



  #4  
Old November 27th, 2007, 07:26 PM posted to microsoft.public.access.forms
Chrisso
external usenet poster
 
Posts: 92
Default How do I access the controls on one form from the code module ofa

On 27 Nov, 18:32, Dale Fye wrote:
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").B ackColor = 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.

"Chrisso" wrote:
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


Thanks RG and Dale. Cheers Chrisso
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.