Running a macro to open a form when query is executed

D

Donna

I have a query that has a parameter that is chosen from a listbox on a form. I need the form to open evertime the query is executed. How do I make it do that?
 
K

Ken Snell

You don't. Instead, have the query be the recordsource of the form, and have
your macro just open the form (not open the query). When the form opens,
it'll run the query.

--

Ken Snell
<MS ACCESS MVP>

Donna said:
I have a query that has a parameter that is chosen from a listbox on a
form. I need the form to open evertime the query is executed. How do I
make it do that?
 
D

Donna

But nobody will ever open the form manually. There is just a group of queries that people choose to run so if someone wants to run the attribute query, I need the form to open to enable them to choose which attribute to filter on
 
K

Ken Snell

Can you provide more details? What I'm reading at the moment is that your
users can choose which query to run (via a form? via the database window?),
and then you want to allow them the ability to decide on which "attribute"
(meaning field?) they can filter the results?

What I think you want to do is to open a form that allows the user to select
the desired "filter" info, and then have the query use the value
chosen/entered on that form as the criterion value for the query's field?


--

Ken Snell
<MS ACCESS MVP>

Donna said:
But nobody will ever open the form manually. There is just a group of
queries that people choose to run so if someone wants to run the attribute
query, I need the form to open to enable them to choose which attribute to
filter on
 
D

Donna

This database is not really set up to be an "application". Mostly what's happening is that they are exporting the data into Excel & playing with it there. The particular query in question has a field that contains attributes of a record. It can have up to 4 different attributes in that field (I know, bad database design, but that's the way their raw data comes in.) I can do Like "*" & "RIC" & "*" to find all the records that contain the RIC attribute. However, as soon as I try to do that using the [Enter Attribute] method, it doesn't work. So I was reading the discussion group topics & saw where you recommended to someone else that they set up an form that lists the different options. So I did that. Now I just need to get the form to open as soon as the query is clicked on so the user can type in the attribute & then run the query. What's funny about all this is when I now run the query, I get a dialogue box that is titled: "Enter Parameter Value", and says "Forms!frmAttribute!Attribute". Obviously, it's wanting the value from the form, but I can type in the search criteria in that dialogue box & it runs perfectly. It's just that the wording in the box doesn't make sense to a user.
 
K

Ken Snell

You need to open the form, not the query. On the form, enter the value into
the textbox. Then have a command button on the form that you click to "run"
the query. The box that you are seeing ("Forms!frmAttribute!Attribute") is
the query asking for the parameter that it wants to read from your
form...but the form is not open so it asks the user for the value.

You're headed in the right direction!

--

Ken Snell
<MS ACCESS MVP>

Donna said:
This database is not really set up to be an "application". Mostly what's
happening is that they are exporting the data into Excel & playing with it
there. The particular query in question has a field that contains
attributes of a record. It can have up to 4 different attributes in that
field (I know, bad database design, but that's the way their raw data comes
in.) I can do Like "*" & "RIC" & "*" to find all the records that contain
the RIC attribute. However, as soon as I try to do that using the [Enter
Attribute] method, it doesn't work. So I was reading the discussion group
topics & saw where you recommended to someone else that they set up an form
that lists the different options. So I did that. Now I just need to get
the form to open as soon as the query is clicked on so the user can type in
the attribute & then run the query. What's funny about all this is when I
now run the query, I get a dialogue box that is titled: "Enter Parameter
Value", and says "Forms!frmAttribute!Attribute". Obviously, it's wanting
the value from the form, but I can type in the search criteria in that
dialogue box & it runs perfectly. It's just that the wording in the box
doesn't make sense to a user.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top