G
Guest
I'm currently working at migrating a large Access 97 application to Access
2003. One of the differences between the two versions that I've come across
is the use of the QueryDef.OpenRecordset method when the QueryDef has
parameters.
Here is some sample code that works fine in Access 97:
Dim db As Database
Dim qd As QueryDef
Dim rs As Recordset
Set db = CurrentDb
Set qd = db.QueryDefs("qxtbTest")
qd.Parameters(0) = 1
qd.Parameters(1) = 5
Set rs = qd.OpenRecordset()
However, this code does not work in Access 2003. The last line results in
an "Invalid argument" error message. I've tried explicitly specifying the
type and options arguments in the OpenRecordset method call with the same
results.
I have not found any entries in the knowledge base and am wondering if
anyone else can confirm this change in behaviour? I'm not sure what the
behaviour is in Access 2000 or 2002 as I do not have access to those versions.
Finally, it looks like I'll need to find another way to write this code in
Access 2003 and am just wondering if anyone has suggestions for me. The
point of the code is that I'm using a crosstab query as the RecordSource of a
report. Since a crosstab can return a varying number of columns, I open a
recordset in the report's Open event with the crosstab query so I can
determine how many columns there are and what the caption should be of each
of the variable columns.
One option would be to avoid using parameters in the query by modifying the
query's SQL each time just before I open the report to use the new values in
the WHERE clause of the query. I'd prefer to find another approach, since
I've found that this technique is difficult to document and causes problems
later in code maintenance. Any better ideas? Would this code work if
rewritten in ADO?
Thanks,
David Kroeker
Programmer/Analyst
B.Sc. Computer Engineering
2003. One of the differences between the two versions that I've come across
is the use of the QueryDef.OpenRecordset method when the QueryDef has
parameters.
Here is some sample code that works fine in Access 97:
Dim db As Database
Dim qd As QueryDef
Dim rs As Recordset
Set db = CurrentDb
Set qd = db.QueryDefs("qxtbTest")
qd.Parameters(0) = 1
qd.Parameters(1) = 5
Set rs = qd.OpenRecordset()
However, this code does not work in Access 2003. The last line results in
an "Invalid argument" error message. I've tried explicitly specifying the
type and options arguments in the OpenRecordset method call with the same
results.
I have not found any entries in the knowledge base and am wondering if
anyone else can confirm this change in behaviour? I'm not sure what the
behaviour is in Access 2000 or 2002 as I do not have access to those versions.
Finally, it looks like I'll need to find another way to write this code in
Access 2003 and am just wondering if anyone has suggestions for me. The
point of the code is that I'm using a crosstab query as the RecordSource of a
report. Since a crosstab can return a varying number of columns, I open a
recordset in the report's Open event with the crosstab query so I can
determine how many columns there are and what the caption should be of each
of the variable columns.
One option would be to avoid using parameters in the query by modifying the
query's SQL each time just before I open the report to use the new values in
the WHERE clause of the query. I'd prefer to find another approach, since
I've found that this technique is difficult to document and causes problems
later in code maintenance. Any better ideas? Would this code work if
rewritten in ADO?
Thanks,
David Kroeker
Programmer/Analyst
B.Sc. Computer Engineering