Passing values between forms

Dave E

Registered User.
Local time
Yesterday, 16:01
Joined
Sep 23, 2019
Messages
139
Hi guys,

I have a main form that has two subforms, PlantList & MainView - the list shows the Latin Plant names and MainView shows data associated with the Latin name. Clicking on the list name will show the info in the other.

I use an unbound field [ID] on the main form as link for the 2 subforms.

Now, I have created another form used to carry out a multitude of search options and end up with filtered list. The Search form changes the unbound field [ID] which accurately selects the right data in the MainView form. No problem.

The problem I'm having is that I need to get the list name record in PlantList highlighted by changing the record selection in the list from the Search form before it closes.

I am using - (from the Search form - )

Code:
Dim SearchID As Integer
SearchID=Me.CurrentRecord

Forms!MainOptions!PlantList.SetFocus
Forms!MainOptions!PlantList.Form![LatinName].SetFocus
DoCmd.GoToRecord acActiveDataObject, , acGoTo, SearchID

I think it needs a trigger, an event, on the receiving list form but I'm having no luck finding it.

Any thoughts?

Regards

Dave E
 
Last edited by a moderator:
Hi Dave. Not sure I follow, but if you simply want to "select" a specific item from a list using a value, then you should be able to try something like:
Code:
Forms!FormName.ListName=YourValue
 
Not quite what I'm after. I don't want to change the record fields but to change the focus of the record so that the conditional highlighting will work. It also keeps the name in the list form synced with its fields in the MainView form.

The problem lies with getting an event to trigger the action of setting the focus on the list name to change the highlighted record so it matches its fields.

Dave E
 
Not quite what I'm after. I don't want to change the record fields but to change the focus of the record so that the conditional highlighting will work. It also keeps the name in the list form synced with its fields in the MainView form.

The problem lies with getting an event to trigger the action of setting the focus on the list name to change the highlighted record so it matches its fields.

Dave E
Hi Dave. As I was saying, it's hard to follow what you're saying without seeing it. Are you able to post a sample copy of your db to show us what's happening?
 
Hi guys,

I have a main form that has two subforms, PlantList & MainView - the list shows the Latin Plant names and MainView shows data associated with the Latin name. Clicking on the list name will show the info in the other.

I use an unbound field [ID] on the main form as link for the 2 subforms.

Now, I have created another form used to carry out a multitude of search options and end up with filtered list. The Search form changes the unbound field [ID] which accurately selects the right data in the MainView form. No problem.

The problem I'm having is that I need to get the list name record in PlantList highlighted by changing the record selection in the list from the Search form before it closes.

I am using - (from the Search form - )

Code:
Dim SearchID As Integer
SearchID=Me.CurrentRecord

Forms!MainOptions!PlantList.SetFocus
Forms!MainOptions!PlantList.Form![LatinName].SetFocus
DoCmd.GoToRecord acActiveDataObject, , acGoTo, SearchID

I think it needs a trigger, an event, on the receiving list form but I'm having no luck finding it.

Any thoughts?

Regards

Dave E

Please see Attached:- PassingValBetweenForms_1a.zip
 

Attachments

Last edited:
Gizmo,

Thanks for the response. The example you supplied is a basic link, on a form, between a combo and two subforms.

I have a Form with two subforms. One subform has just a list of names for selection, in a Continuous Form. So, all my names appear in a scrollable list. When a record is selected, it is highlighted, by conditional formatting, and is linked, via an unbound ID field, on the mainform to the other subform which shows the full data set, in a similar way to your example. All this works well.

On another form (SearchOptions), opened by a Main Form button, a pile of search options results in a list of filtered records. Hitting a button sends the ID of any of the selected filtered records back to the Main form where the mainform Id is updated, which changes the data in the second form to suit the new ID.

But now, the selected, and highlighted, record in the list form does not now correspond with the dataset in the other form. I tried to use code on the searchform, see above, which works fine if I run it from the OnLoad event in the list form (as a test) but not from the search form.

Because the code is running from another, separate form, there seems to be a failure in changing the focus in the list subform, which I think is a lack of a trigger or event.

What do you think?

Dave E
 
I will create a similar set up as an example and upload, if possible, tomorrow.

Thanks for your help thus far.

Dave E
 
Thanks for the response. The example you supplied is a basic link, on a form, between a combo and two subforms.

No, it's not ... Have a better look....

The combobox controls the records displayed in the subform on the left and the subform on the left controls the records displayed in the subform form on the right. The Subform on the right is NOT directly linked to the Combo Box.



Sent from Newbury UK
 
I will create a similar set up as an example and upload, if possible, tomorrow.

Thanks for your help thus far.

Dave E
Hi Dave. If you get a chance to do so, we'll make sure to take a look for you and help you get what you wanted. Cheers!
 
Maybe something like
Code:
Forms!MainOptions!PlantList.Form.recordset.findFirst "SomeIDField = " & me.SomeIDField
 
Last edited:
I tried to use code on the searchform, see above, which works fine if I run it from the OnLoad event in the list form (as a test) but not from the search form.

I too am having trouble picturing your situation.

I think you are saying that the code works fine if you run it in the OnLoad event in the list Form. And I think the list Form is one of two subforms on a Main Form.

If that's the case, then you need to put your code in its own PUBLIC Function. Make sure the PUBLIC Function works by calling the function from the onload event, it should work just as it did before when the code was in the onload event. You're just testing to make sure everything works ok.

Now you need to call this public function from your search form.

It's not straightforward because you have to sort of jump through hoops!

The "Main Form" houses the "List Form" but the list form isn't directly on the main form, it's housed within a subform/subreport control. The Microsoft default name for this control will be the same as the form it houses, the form contained within it, and it's very confusing!

So I assume your subform/subreport control will house a form called something like "List Form" or whatever you have named it. It is very likely your subform/subreport control will be named "List Form" as well. It's a very good idea to immediately name these subform subreport controls to something more sensible like:- "subFrmWinListForm"

Read subFrmWin as sub-form-window...

Now the fun starts, to call the "PUBLIC Function" you call the main form then you call the subform window. Then you identify the form within it with the subform/subreport Control (subform window) with "Form" and then you call the actual public function.

So the code will look something like this:-

MainForm.subform/subreport control.Form.fMyPublicFunction

MainForm.subFrmWinListForm.Form.fMyPublicFunction

Sent from Newbury UK
 
Last edited:
Thanks to MajP, once again for the solution to my problem. And to the others for their useful input. I am very grateful.

Kind Regards

Dave E
 
Thanks to MajP, once again for the solution to my problem. And to the others for their useful input. I am very grateful.

Kind Regards

Dave E

Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom