Microsoft Access - Can a parameter query be opened through vba?

Asked By Pete Bradshaw on 19-Jul-12 06:01 AM
Pat Hartman replied to Pete Bradshaw on 25-Jul-12 03:58 PM
What do you mean - opened?  Are you asking how to use a parameter query to open a recordset?  The answer is yes.  Here's some DAO code.  In the sample below, [EnterProdID] and {EnterWarehouseID} are the parameter names in the query.  If you have used spaces in yours (I never do), you'll have to enclose them in square brackets in the code.  The "Me.cboxxx" references are to comboboxes on the current form.
Dim db as DAO.Database
Dim qd as DAO.Querydef
Dim rs as DAO.Recordset
 
Set db = CurrentDB()
Set qd = db.QueryDefs!qIssueInventory
    qd.Parameters!EnterProdID = Me.cboProdID
    qd.Parameters!EnterWarehouseID = Me.cboWarehouseID   
Set rs = qd.OpenRecordSet
 
Do Until rs.EOF = True
  'do something  
  rs.MoveNext
Loop
rs.Close