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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Query results for current record only.

Status
Not open for further replies.

mattborn

Technical User
Jul 9, 2002
19
US
I have two tables. The primary key in the first table is 'PrjName' and it has a one-to-many relationship with the corrsponding field name in the second table. Everything works fine except when I want to run a query.

I have a button on the form for the second table to run a quesry.
I need the query to only display the results that have the same 'PrjName' as the 'PrjName' in the current record.

Right now, when I run the query it displays all the records, no matter what the 'PrjName' is.

I know I can hard code the criteria, but I want to beable to run this quesry from any record.

Please help.
 
In the criteria of the prjname column of query you are calling use

<<<Start Code>>>

Forms![Form1]![Text4]

<<<End Code>>> do not use this line

Where Form1 = the name of the form in your DB
and
Where Text4 is the name of the control that holds the prjname.

Good luck
ssecca
 
Try adding a criteria to the query like this:

=Forms![nameofyourform]![PrjName]

Save the query with this criteria so every time it is invoked, it will use the project name on the current record of the form as the criteria.
 
I tried those ways mentioned above, but when the query is ran a box pops up asking for parameter value. If I type in what I want it works, but I need it to work automatically.
 
OK, Here is some more info:
Screenshot is attached below.

I have one main form called [frm_Main Page], and as you see below I have tabs setup, and each tab has its own form in it. For example, the Fees form has [frm_Fee TAB] in it. I currently have the above suggestions in the criteria, and I get the desired results when I load up the [frm_Fee TAB] form and run the query, but when I load up the main form, [frm_Main Page], and go to the Fee tab the query doesn't work, it asks for the parameter value.

PLEASE HELP!

access.jpg
 
Modify my Forms!formname... from earlier to include the subform name from the main form. The coding that I gave you was depending on the fact that the field used for the criteria was in the main form:

=Forms![nameofyourmainform]![nameofyoursubform]![PrjName]

This should work.
 
For Mattborn,

You need to leave the form open while opening the query..

Thank you.
 
wemeier,

I appreciate your help, I thought your last suggestion would work, but i still get a box thats asks for parameter value. Any other ideas? Does it make a difference that the subform is on a TAB?
 
No, I set up a field with a page control containing a subform and it works perfectly. As hassanmfsa said, you have to have the form open while the query is running. Other than that, make sure you've spelled everything correctly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top