Hi everyone,
I am writing a VBA code to try and modify my query criterion and I'm using QueryDefs and Parameters for that. Unfortunately, I have run into 2 problems:
1) I need to use a conditional criterion, e.g. >date( )-7 and I don't know how to use Parameters for a criterion that is neither a string nor an integer type.
2) Then I use OpenQuery to run my query, but it seems to ignore the parameter change that was done previously using Parameter (I tried with an integer criterion because I didn't know how to do the conditional criterion for this...)
Below is the code that I wrote.
Hopefully that made sense and thank you in advance!
K.
I am writing a VBA code to try and modify my query criterion and I'm using QueryDefs and Parameters for that. Unfortunately, I have run into 2 problems:
1) I need to use a conditional criterion, e.g. >date( )-7 and I don't know how to use Parameters for a criterion that is neither a string nor an integer type.
2) Then I use OpenQuery to run my query, but it seems to ignore the parameter change that was done previously using Parameter (I tried with an integer criterion because I didn't know how to do the conditional criterion for this...)
Below is the code that I wrote.
Hopefully that made sense and thank you in advance!
K.
Code:
Option Compare Database
Private Sub Command0_Click()
On Error GoTo Command0_Click_Err
Dim QDF As DAO.QueryDef
Set QDF = CurrentDb.QueryDefs("QRY_a")
QDF.Parameters("week_to_query") = ">=Date()-7"
DoCmd.OpenQuery "QRY_a", acViewNormal, acEdit
Command0_Click_Exit:
Exit Sub
Command0_Click_Err:
MsgBox Error$
Resume Command0_Click_Exit