thick_guy_9
New member
- Local time
- Today, 22:57
- Joined
- Jun 21, 2009
- Messages
- 7
Dear All
I inherited an ACCESS application that has a SELECT query with hard-coded parameters.
i.e where (((TABLE.YEAR=2007)))
By going to the Query Designer, I have added a criteria [What YEAR] that prompts for year when the query is opened.
To do this in VBA, I did the following to pass the parameters:
-----------------------------------------
Private Sub cmdQuery_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim parm As DAO.Parameter
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set qdf = db.QueryDefs("myqryrel")
qdf.Parameters("WHICH YEAR") = "2009"
qdf.Parameters("WHICH COLOUR") = "YELLOW"
Set rs = qdf.OpenRecordset
'DoCmd.OpenQuery "MYQRYREL"
End Sub
----------------------------------------------
NOW how do I display the results of the Query?
DOcmd.openquery.... again prompts for the values, so it is not an option.
I want to pass the parameters to the query and view the filtered results.
Please note that constructing the SQL is not an option as the user has indicated that they want to be able to add some columns using QUERY designer.
Thanks in advance
I inherited an ACCESS application that has a SELECT query with hard-coded parameters.
i.e where (((TABLE.YEAR=2007)))
By going to the Query Designer, I have added a criteria [What YEAR] that prompts for year when the query is opened.
To do this in VBA, I did the following to pass the parameters:
-----------------------------------------
Private Sub cmdQuery_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim parm As DAO.Parameter
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set qdf = db.QueryDefs("myqryrel")
qdf.Parameters("WHICH YEAR") = "2009"
qdf.Parameters("WHICH COLOUR") = "YELLOW"
Set rs = qdf.OpenRecordset
'DoCmd.OpenQuery "MYQRYREL"
End Sub
----------------------------------------------
NOW how do I display the results of the Query?
DOcmd.openquery.... again prompts for the values, so it is not an option.
I want to pass the parameters to the query and view the filtered results.
Please note that constructing the SQL is not an option as the user has indicated that they want to be able to add some columns using QUERY designer.
Thanks in advance