Open query with parameters in vba

  • Thread starter Thread starter JohnnY
  • Start date Start date
J

JohnnY

Guest
I have to open a recordset based on a query
and this query has a parameter :
Forms![formular pe ani]![yearid]
 
In the sample below gProdOrder is a global variable that was set elsewhere. In your case it would be the reference to a form field.

Dim WgtDB As Database
Dim QD1 As QueryDef
Dim TempSet1 As Recordset
Set WgtDB = CodeDb
Set QD1 = WgtDB.QueryDefs!QProdOrdersReprint
QD1.Parameters![ProdOrder] = gProdOrder
Set TempSet1 = QD1.OpenRecordset
 
Hi Pat,
this is very helpful to me too. Could you tell me how this situation would look like if the parameter was not in the query that you actually wanted to open but in a previous query that this one refers to.

Thanks for the help.
 
The parameters are "passed through" to the underlying queries. No changes to the code are necessary.
 

Users who are viewing this thread

Back
Top Bottom