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

Run parameter query from button click?

Status
Not open for further replies.

jazminecat

Programmer
Jun 2, 2003
289
US
Hi - I have a parameter query that I want to run from a button on a simple form. The parameter query only takes a yes or no, and then results are returned based on that. The form has an option group called SubRecipYN, where the user selects on of the two items.

I need to then pass that selection to a parameter query called SubrecipientReport. This query will be used to populate a report. (down the line, this button click will also open that report, but for now, I just want to run that report's source query.

I am unable to even figure out how to open thw query, so I'm either clueless or not awake. I have this in the onclkick even of the button on my form:

Code:
Private Sub cmdRunQry_Click()
On Error GoTo Err_cmdRunQry_Click

DoCmd.OpenQuery (SubrecipientReport)




Exit_cmdRunQry_Click:
    Exit Sub

Err_cmdRunQry_Click:
    MsgBox Err.Description
    Resume Exit_cmdRunQry_Click
    
End Sub

But even this it says the action or method requires a Query Name or argument.

If I use this line:

DoCmd.OpenQuery (SubrecipientReport,acViewNormal,acEdit)

when I try to close the vb window it says it's expecting an = so there appears to be more required than this? Can anyone point me in the right direction here?

thank you!

 
It is not that clear, alright. The query name is text:
Docmd.OpenQuery "SubrecipientReport
 
<hangs head in shame> I should have know that. Really I should have.

ok, so sweet, that opens the query, well it pops up the query's parameter window asking for the parameter. Now how do I pass the selection from the option buttons to that parameter window and just run the query?

Of course, now i am thinking maybe it would be better to have the sql in this vb code than in a separate query, huh? Would that make it easier to pass the parameters from this form, right into the sql statement, and then run the sql based on that? just musing, not like I know how to do that or anything...but I could work with it if that's a better way.
 
If you are using option buttons, code might be best. Have you seen:
Build Report Criteria via a Form w/list box, text box, date range
faq181-5497
 
very cool - I will work with this idea and if I get stuck, you know I'll be back. thanks for the link!!!
 
Perhaps you could reference the option group from your form in your queries WHERE clause?

i.e.
Code:
SELECT *
FROM tblYourTable as t
WHERE t.[SubRecip_Field] = Forms![frmYourForm]![SubRecipYN]

...or something to that effect.


~Melagan
______
"It's never too late to become what you might have been.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top