
For example:
Function SetRecordset(frm As Form, queryname As String)
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Set db = CurrentDb
Set qdf = db.QueryDefs(queryname)
qdf.Parameters("parExamDateStart") = #2/1/2025#
qdf.Parameters("parExamDateEnd") = #12/31/2025#
Set rst = qdf.OpenRecordset(dbOpenDynaset)
Set frm.Recordset = rst
End Function
Call like this:
Call SetRecordset(Me, "qryParameterTest2")
If you wish, you can also pass the parameter names and values to the function.