Customising a Parameter Query

  • Thread starter Thread starter Bloodsoul
  • Start date Start date
B

Bloodsoul

Guest
Sorry I am new to this game, never done any programming before.

I have followed these instructions thats creates a query based on a combo Box in a from.
http://www.fontstuff.com/access/acctut08.htm
Everything works great. see code below.

Option Compare Database

Private Sub cmdcancel_Click()
DoCmd.Close acForm, "frmQuery"
End Sub

Private Sub cmdOK_Click()
DoCmd.OpenQuery "qryQuery", acViewNormal, acReadOnly
DoCmd.Close acForm, "frmQuery"
DoCmd.Close acQuery, "qryQuery"

End Sub

My Question is how can I use the results of the query "qryQuery" in a form.

Althought the Query has the Info I require, I can't access the query as a dialog box opens.
I presume it is possible to do this but I do not know the code required. :confused:

Any help would be much appreciated. :D
 
Bloodsoul said:
My Question is how can I use the results of the query "qryQuery" in a form.

Set the query to be the Form's RecordSource...

Unless you mean something else.
 
Maybe I need to explain a bit more.
The data in the query is based upon a combobox in a form, so the query data is always changing depending upon what you select from the combobox.

When I Set the query to be the Form's RecordSource a dialog box appears asking for a parameter. If I select the same parameter as the combobox the form will open.

Although the query Displays the right data when you make a selection from the Combobox, it seems that the data in the query is not saved.

If you try and open the query on its own again a dialog box appears asking for a parameter. If I select the same parameter as the combobox the query will open.

What additional code is required to allow the displayed data in the query to be used in another form?

I hope all this makes some sense.

Thanks
 
I've answered some of your quesitons below. However, I can tell from them that this technique is not what you want. You obviously want it to do something that it wasn't designed for. What exactly are you trying to accomplish? Why reference a value in a form combo box if it seems you want to place a literal criteria value in there?

The data in the query is based upon a combobox in a form, so the query data is always changing depending upon what you select from the combobox.
Exactly. That's one of the advantages of using a query with criteria supplied by a combobox: it's really easy to change the criteria.

When I Set the query to be the Form's RecordSource a dialog box appears asking for a parameter.
I'm confused as to why that's happening. Are you doing it in code or in the form's property sheet in design view?

If I select the same parameter as the combobox the form will open.
Again. Confused as to what you mean. You're selecting a parameter from the form's combo box? But aren't you selecting the combo box to be your parameter in the query?

Although the query Displays the right data when you make a selection from the Combobox, it seems that the data in the query is not saved.
What do you mean? You want to save the query as is? Based on the selection in the combo box? It doesn't work that way. Not unless you physically change the form reference from Forms!yourform!yourcontrol to the literal value.

If you try and open the query on its own again a dialog box appears asking for a parameter. If I select the same parameter as the combobox the query will open.
That's exactly what should happen.
 
I have a form (all it realy is is a dialog box). So you can select criteria from a comboBox and then press an "ok" button. the code above is from the OK button. The Query then opens fine, with the selected data showing. This all works.

What I would like to do now is be able to view the results of that query in another Form. So evertime you select a differant criteria from the Dialog box that data would then be able to be viewed by using a form.

The Hyperlink above shows you what I have done so far
 

Users who are viewing this thread

Back
Top Bottom