Passing a Parameter

Srussom

Registered User.
Local time
Today, 13:04
Joined
Apr 10, 2018
Messages
15
Hi All,
I have a Main Form which shows summary of main information in Continuous Form format. In this Form there is a column for a button when clicked takes you to Detailed Form to display detailed information in Single Form format, the data for this comes from a query. I want to pass the ID of the Main Form to the Query Criteria to filter and display the detailed information of the particular record in a Main Form.
At the moment when I clicked on the button it opens Detailed Form of the first record only even though I clicked on different record in the Main Form.

I sincerely appreciate your help.

Regards

Solomon
 
Generally forms pass information to each other on opening using the OpenArgs parameter of the OpenForm Method. The called form can then read its own OpenArgs Property to retreive what has been passed.

However there are other ways to do what you require.

One is to refer to the textbox on the calling form in the RecordSource query of the opening form.

Another is to set the Recordset property of the called form to the Recordset Property of the calling form. Whatever happens in either form is reflected in the other.
 
You need a reference to the main form in the query.
Open the query in design view, click the ID field, then in the criteria click the "Builder", (it is in the Query Setup - group in the Ribbon).
Or type in the reference to the control at the main form manually.
 
Re: Passing a Parameter Further clarification

I am just trying to clarify what I want to do. please see the attached


Thank you for your help.

Solomon
 

Attachments

I've made an example for you.
Galaxiom explain some other ways.
 

Attachments

JHB and Galaxiom, Many thanks for your help. At the moment I am trying to modify the Form. Hope it works. I will let you know.

Many thanks again for your time and expertise

Solomon
 
The OpenForm method takes a WHERE argument. Use that to open the form.
 
Hi JHB, Galaxiom and Pat Hartman,
It worked well, Thank you so much for your help.
 
Hi JHB,
Your example worked well as I said last week when the Record Source is a table (Scheme in my case). But if the Record Source is a Query Table (QScheme) in my case, it doesn't work.
[Forms]![Scheme]![SchemeID] in the Query Criteria is not filtering the required records when the Record Source of the Form is a query.
Just to explain the whole story:
1) I have a table called Scheme
2) I created a query with fields from the Scheme table called (QScheme)
3) I created a Continuous Form called FScheme pulled from fields from QSchemes.
The detailed information of each record in Continuous Form FScheme is contained in a Query table called QAllocation. When I clicked a button in the Continuous Form FScheme I want to open QAllocation filtered by SchemeID.
I used [Forms]![Scheme]![SchemeID]. But this works well if the Record Source of the Scheme Form is a table but if it is a query, it doesn't work. Any Idea please.
Kind Regards
Solomon
 
so your query needs to know about the current main forms ID. There are many ways to do this. For me, I would create a global variable, e.g. public glng_MAIN_ID as long into a Public module then I would create a GET function so that the query can just run the function and collect the ID.
something like this:
Code:
Public Function Get_MainID() as long
Get_MainID = glng_MAIN_ID 
end function
Then in your query we need to add the function call in the MAIN_ID columns criteria.
i.e. Criteria = Get_MainID()

And the last thing to do is to set our global variable every time you move to a new record on the Main Form. So in the form current event of the form put
glng_MAIN_ID = me.MainID

All done
 
..
..But if the Record Source is a Query Table (QScheme) in my case, it doesn't work. ...
The sample database I posted is based on a query. :)
Could you post your database with some sample data, zip it?
 
Hi JHB,
Thanks for getting back. I double checked your example. The Record Source of tblMain Form is tblMain table (not a query).
 
I attached a new sample, (main form based on a query).
You write that "Continuous Form called FScheme" and that you use "[Forms]![Scheme]![SchemeID]", I don't know if it is a typo, but the form's name differ.
Else post your database with some sample data.
 

Attachments

Users who are viewing this thread

Back
Top Bottom