Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a value from one form to another form

Status
Not open for further replies.

fchan

MIS
Jul 2, 2001
47
US
Hi,

This question involves three forms in my application.

Form 1 is a search form. When an ID is entered, a table in my database is queried. If the ID is found, I use the Open method of the DoCmd to open form 2.

The recordsource for Form 2 is then dynamically created using an SQL statement, passing the ID from Form 1 into the SQL statement. Form 2 also has a subform (Form 3).

I'm trying to pass a value from a field on Form 2 to Form 3 when Form 3 loads. However, because the recordsource for Form 2 is dynamically generated, when Form 3 loads it can not read the values in any of the fields on Form 2.

Does anyone have any suggestions? Or is this too confusing.
 
Set the value to a global variable then use the global for form 3's field.
 
Thanks ToeShot,

But where do I assign the global variable the value I want it to hold? I tried assigning the global variable a value within a sub procedure and Form 3 couldn't read the value.
 
Hi!

Try this:

Instead of dynamically creating the recordsource for Form2 and form3, use a standard form/subform setup, assuming your data is conducive to that. Then, when you open the form from form1 you can filter the data like this:

DoCmd.OpenForm "Form2", , "Id = '" & txtID.Value & "'"

I think the reason you are having trouble setting the value you want is that the subform actually opens and loads before the form does. If you really must set the value after the forms are loaded, then you can do it in the form2_Load procedure or possibly in the form2_Current procedure.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Under you option compare statement at the top of your code enviroment behind the form you are coding.

HTH

If you need more help let me know.
 
Sorry to jump into your post but I think that I have a similar problem (I've posted in the VBA section but to no avail).

What I'm trying to do is pass the value of a field (MaidenName) that is entered onto a pop-up form onto the form below into a field of the same name (MaidenName).

I've tried the following code in the afterupdate_event procedure but it doesn't work:

Forms!frmClients!MaidenName = Forms!frmApplication!MaidenName

Do you guys have any other ideas?

Thanks in advance,
Ryan.
 
Some questions first this pop up form am I correct to assume that you are using the code on the afterupdate on the pop-up form? second is the frmClients the pop up form or is the frmapplication? This may sou like a stupid question but I must ask it. is the form you are trying to send the value too open? If it is can you just directley type th value into it and avoid the pop-up? I need a little more clarity on what it is you are presently doing and what you are trying to acheive.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top