T
Tod
I have the following code:
With cm
.ActiveConnection = cn
'Where VariableForQueryName is the name of the query
exactly as it appears in my Access database
..CommandText = VariableForQueryName
.CommandType = adCmdStoredProc
'OtherInputField is the name of the field in the query.
Set pm1 = .CreateParameter(OtherInputField,
adInteger, adParamInput)
.Parameters.Append pm1
'ReportMonth is a variable that holds the month number as
an integer
.Parameters(OtherInputField) = ReportMonth
Set pm2 = .CreateParameter(OtherInputField,
adInteger, adParamInput)
.Parameters.Append pm2
.Parameters(OtherInputField) = ReportYear
End With
rs.Open cm
So what this does is create two parameters, one for month
and one for year and passes those parameters to my Access
query into a field that prompts for those two values. It
then returns the Recordset for me to work with. In the
Access database, the above-mentioned query includes a an
access table that is linked to an Excel workbook.
The problem is that this statement:
rs.Open cm
is opening the workbook that is for the linked table
instead of returning the recordset from the query.
If I run the query myself it works fine. I also use the
same code for other queries and it works fine for them.
Why would the workbook open?
tod
With cm
.ActiveConnection = cn
'Where VariableForQueryName is the name of the query
exactly as it appears in my Access database
..CommandText = VariableForQueryName
.CommandType = adCmdStoredProc
'OtherInputField is the name of the field in the query.
Set pm1 = .CreateParameter(OtherInputField,
adInteger, adParamInput)
.Parameters.Append pm1
'ReportMonth is a variable that holds the month number as
an integer
.Parameters(OtherInputField) = ReportMonth
Set pm2 = .CreateParameter(OtherInputField,
adInteger, adParamInput)
.Parameters.Append pm2
.Parameters(OtherInputField) = ReportYear
End With
rs.Open cm
So what this does is create two parameters, one for month
and one for year and passes those parameters to my Access
query into a field that prompts for those two values. It
then returns the Recordset for me to work with. In the
Access database, the above-mentioned query includes a an
access table that is linked to an Excel workbook.
The problem is that this statement:
rs.Open cm
is opening the workbook that is for the linked table
instead of returning the recordset from the query.
If I run the query myself it works fine. I also use the
same code for other queries and it works fine for them.
Why would the workbook open?
tod