How to reference a value in a table with a query's criteria

loopa1

Board Regular
Joined
Sep 3, 2006
Messages
156
Hi all
I have a query which includes criteria for a field. Until now this criteria has remained static, there's never been a need for it to be anything else, however, I now what to extend it so that it is based upon a value within a table which is changeable by the user.

The table, called PartnershipSelector, contains one record and field only. The field is called CurrentPartnership and the field value (for the only record in the table) is updated whenever the user selects which partnership they want to report on using a combo box.

So how do I reference this table/field/value in an access query?

I though it would be something like [PartnershipSelector]![CurrentPartnership], but access justs prompts me for this value instead of returning it, so I know I have it wrong.

Thanks.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
On a form create a combo that points to the table and field then set the query criteria to use the combo on the form, remember to name the combo in the properties something like cboSelectName, save the form again something like frmSelectList, then add a command button to open the query.
 
Upvote 0
Thanks Trevor, although I still don't know how to reference the value stored in the combo box.

In the criteria row in my query, I have placed this for the field I want to filter..

[Forms]![frmSelect]![cboSelectName]

Where am I going wrong?
 
Upvote 0
You don't seem to have gone wrong, have you added the command button to open the query?

So you have opened the form, then selected the combo box and made your choice then clicked the button to open the query !
 
Upvote 0
Ah...I know why it was still prompting me for the value, I didn't have frmSelect open.

How can I use this value without having the form open? I think this is why I first thought I'd need to reference the value stored in the table.
 
Upvote 0
You can use code (do you know vba?) or point to the table in the criteria, but you would need to have the table open then same as selecting from the form.
 
Upvote 0
I know a little vba.

I've added the table to my query designed, joined the two fields together, removed the criteria and this seems to work.

I suppose this way achieves what I want given that it's only showing those records where the partnership = the value in my joined table.

Don't know why I didn't think of that sooner!
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top