Passing a value from parent form to child form

GregP

Registered User.
Local time
Tomorrow, 07:04
Joined
Sep 16, 2002
Messages
66
Hi,

I have a parent form which contains information about PCs on our network. In this form is a button which, when clicked, will open a second form and display any licensed software installed on that PC. The heading on the child form is 'Licensed software on <asset number of the PC in question>. If the PC has licensed software installed (i.e. it has an entry in the licensed software table), this works fine, but when there's no licensed software on the machine, the asset number of the machine isn't shown. I can see why this happens, because the asset number doesn't appear in the licensed software table. The correct information is shown by the underlying query (when there is no licensed software, the form is blank as it should be), but the title doesn't show which machine the information is relating to.

What I want to do is simply to pass the asset number from the parent form directly to the child form, disregarding the underlying query which extracts the appropriate data. Can I somehow store the asset number from the parent form into a variable of some sort, and then retrieve this at the other end and have it displayed in the child form?

Greg
 
Can I somehow store the asset number from the parent form into a variable of some sort, and then retrieve this at the other end and have it displayed in the child form?
This is possible, and actually a lot less complicated than it sounds. My question is: why not use a form/subform type of set up so that when you move from machine to machine in the main form, the subform would show the software on that particular machine? Something to consider.

If you are clicking a button on the main form, then you can pass the information you want to another form using the OpenArgs parameter of the DoCmd.OpenForm method. The Access on-line help has all the info you need. In fact, you don't even really need to pass any info to the other form. The other form can take the info directly off the main form by referencing the field with the asset number of the PC. Say the asset number is in a control called "txtAssetNum" on the form called "frmMainForm". From the form that pops up, you can reference that field like this:
Code:
Forms("frmMainForm")("txtAssetNum")
To set a control on the pop up form equal to that field value, use code like this:
Code:
MyField=Forms("frmMainForm")("txtAssetNum")
 
I don't want to use a subform in this case, because the information won't be needed that often, so I'd rather have it accessible by just a button rather than a permanently displayed subform. It's also neater for the form layout I have.

I couldn't actually get either of those methods to work, but I don't doubt there's something wrong in my implementation.

I tried the =Forms(..... in the control source of an unbound text box called TestEE

I put Me.TestEE.text = Forms(..... in the form.load and TestEE BeforeUpdate (Cancel as Integer) properties

Is that what I was supposed to do?
 
I put Me.TestEE.text = Forms(..... in the form.load and TestEE BeforeUpdate (Cancel as Integer) properties
No need to use the .text property of the control. The default .value property is the one you need. You can just say Me.TextEE = Forms(.....
 
Hmm, still no go. I get a runtime error when I put:

Me.TestEE = Forms ("frmInventory") ("EE_No")

in the Form.Load property, and it doesn't do anything in the TestEE.BeforeUpdate (Cancel as Integer) property. I also put the same thing in the control source of an unbound text box, but that didn't do anything either.

Where exactly is it supposed to go?

With it just in the control source, it does give me the correct result in the unbound field, but only when I click on a machine for which a record already exists in the target query, which is what I had before already. So maybe it's still trying to take the value from the current (child) form instead of from the parent?
 
Last edited:
Me.YourControlName = Forms!YourFormName!YourControl
or from the initial form
Forms!YourForm!YourControl=Me.SomeControl
 
That works, but again only if the child form has a record matching the machine currently shown in the parent form. I need the child form to take the field value and display it from the parent form, regardless of whether there's a matching record or not. Another thought, can the parent form maybe store the value in a variable somewhere so the child form can then read it back?
 
Use a query as the recordsource for the popup form. Join the maintable to the subform table with a left join. That way, you'll see the selected maintable record even when there are no matching subform records. Then by simply using bound fields, you will be able to display certain mainform data on the popup form.
 
Hi Pat,

Yes, that worked! I had tried something similar in my early investigations, but kept getting an error message about an ambiguous outer join (there are three tables in my query) which only came when I changed the matching join on the 2nd and 3rd tables to a left join. But when I changes the join on the 1st and 2nd tables to a left join also, it worked fine. Must say I'm not sure if this will create other issues, but none are apparent so far.

Thanks for your help!

Greg

P.S. Incidently, is there an easy way to store the value of a field into a 'global variable' or something and then have it read back by any other form? I wouldn't have thought it'd be that difficult. I did see some information about this in some other threads, but all the talk about Public functions and Option Explicit databases seemed more confusing than I would have thought it needed to be.
 

Users who are viewing this thread

Back
Top Bottom