Hi everyone,
A bit stuck on how to execute some code. I have a query that searches for records that are between two dates using the WHERE clause. The two dates are referenced to two respective text boxes on a form. On the same form I have a button that will launch the query in VBA using querydefs. I get the error 3061 saying I need to input the parameters (makes sense). Therefore I am a bit unsure how to set the parameters in VBA. So far I have done this:
CODE \\\
Dim Db As DAO.Database
Set Db = CurrentDb
Dim QDef As DAO.QueryDef
Dim rst As DAO.Recordset
Set QDef = Db.QueryDefs("Rqt_F_BrokerageMandate_MF3_TEST")
' Define the parameters
Dim Param As DAO.Parameter
For Each Param In QDef.Parameters
Debug.Print Param
Next
'QDef.Parameters("Date_VL") >= [Formulaires]![F_BrokerageMandate_Main_Formulaire_TEST]![Fees_Start_Date]
'QDef.Parameters("Date_VL") <= [Formulaires]![F_BrokerageMandate_Main_Formulaire_TEST]![Fees_End_Date]
Set rst = QDef.OpenRecordset(dbOpenDynaset) /// CODE
Where Date_VL is the field to be filtered. I know this is wrong but all examples I have seen have equated the parameter to a fixed value i.e 30/12/2012 for example, but I want this to be at the users discression. The only way I know of to get around this at the moment would be to write a temp query in VBA with PARAMETERS in the SQL code instead using the method above/
Any help would be greatly appreciated.
After this I'm going to assign the recordset to a matrix but that's a different story!
Regards,
MOR
A bit stuck on how to execute some code. I have a query that searches for records that are between two dates using the WHERE clause. The two dates are referenced to two respective text boxes on a form. On the same form I have a button that will launch the query in VBA using querydefs. I get the error 3061 saying I need to input the parameters (makes sense). Therefore I am a bit unsure how to set the parameters in VBA. So far I have done this:
CODE \\\
Dim Db As DAO.Database
Set Db = CurrentDb
Dim QDef As DAO.QueryDef
Dim rst As DAO.Recordset
Set QDef = Db.QueryDefs("Rqt_F_BrokerageMandate_MF3_TEST")
' Define the parameters
Dim Param As DAO.Parameter
For Each Param In QDef.Parameters
Debug.Print Param
Next
'QDef.Parameters("Date_VL") >= [Formulaires]![F_BrokerageMandate_Main_Formulaire_TEST]![Fees_Start_Date]
'QDef.Parameters("Date_VL") <= [Formulaires]![F_BrokerageMandate_Main_Formulaire_TEST]![Fees_End_Date]
Set rst = QDef.OpenRecordset(dbOpenDynaset) /// CODE
Where Date_VL is the field to be filtered. I know this is wrong but all examples I have seen have equated the parameter to a fixed value i.e 30/12/2012 for example, but I want this to be at the users discression. The only way I know of to get around this at the moment would be to write a temp query in VBA with PARAMETERS in the SQL code instead using the method above/
Any help would be greatly appreciated.
After this I'm going to assign the recordset to a matrix but that's a different story!
Regards,
MOR