MonteDelMar
asked on
Word VBA - passing criteria to an Access Query
I would like to pass multiple parameters, from Word VBA, when prompted to [EnterCriteria] in the above query. For example, I might want results from all the departments listed in the database, or I may want only results for 'Engineering' and 'Development' ("Engineering" or "Development"). Is that possible or will I have to put the SQL query into my VBA code and pass the parameters that way?
Many thanks for your help.
ASKER
Thanks for your reply, Fabrice.
I am using ADODB and this is what I have. I pass the name of the Query and the value of the Filter to the VBA routine as Strings. In this case it the query would be "qRateDisplay" and the filter would be the name of the department(s).
If I assign the value of the filter to be "Corporate" the query and code work.
If I assign the filter to be "Research & Development" or "Engineering", then it does not work.
How do I pass the string "Research & Development" or "Engineering"? This is my problem. I have tried messing about with the syntax but I have not found the answer.
Many thanks.
I am using ADODB and this is what I have. I pass the name of the Query and the value of the Filter to the VBA routine as Strings. In this case it the query would be "qRateDisplay" and the filter would be the name of the department(s).
If I assign the value of the filter to be "Corporate" the query and code work.
If I assign the filter to be "Research & Development" or "Engineering", then it does not work.
How do I pass the string "Research & Development" or "Engineering"? This is my problem. I have tried messing about with the syntax but I have not found the answer.
With cQuery
.ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = strQuery
If strParameter <> "" And strFilter <> "" Then
Set pParam = .CreateParameter(strParameter, adChar, adParamInput, Len(strFilter), strFilter)
.Parameters.Append pParam
End If
End With
Many thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Basically:
Open in new window