Cannot open query which has a parameter

mholderi

New member
Local time
Today, 20:58
Joined
Jul 22, 2014
Messages
7
Hello,

In Access 2003 I create a query which for one field was link to a value on a form.
Now I have to duplicate this form and instead to duplicate this query I wanted to use a parameter inside this query for one field and then via VBA call this query and give a value for this parameter.

My query name is: Query_Parameter
Fields inside: "Asset_Name" and "Isin"
Parameter is under the "Isin" field: [Look_Isin]

My VBA code is:

Code:
Sub Test_Call_ISIN()
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Set dbs = CurrentDb
'Get the parameter query
Set qdf = dbs.QueryDefs("Query_Parameter")
'Supply the parameter value
qdf.Parameters("Look_ISIN") = "LU0402212806"
'Open a Recordset based on the parameter query
Set rst = qdf.OpenRecordset(dbOpenDynaset)
End Sub

When I run the code nothing happen :confused:

Can someone help me?

Thank you ion advance.
Regards,
Michel.
 
the recordset will have opened in vba - it doesn't open a query window.

So you need to assign it to a form recordsource or control rowsource

e.g. set me.recordset=rst

or cut the rst out completely

set me.recordset=qdf.OpenRecordset(dbOpenDynaset)

you can also add dbfailonerror to generate an error if one exists

Set rst = qdf.OpenRecordset(dbOpenDynaset,dbfailonerror)
 
Hello,

Thank you very much for your answer it's working exactly how I would like.
I didn't know that you cannot open a query but you have to pass the information directly in a list or combobox :o
Michel.


the recordset will have opened in vba - it doesn't open a query window.

So you need to assign it to a form recordsource or control rowsource

e.g. set me.recordset=rst

or cut the rst out completely

set me.recordset=qdf.OpenRecordset(dbOpenDynaset)

you can also add dbfailonerror to generate an error if one exists

Set rst = qdf.OpenRecordset(dbOpenDynaset,dbfailonerror)
 

Users who are viewing this thread

Back
Top Bottom