vB error in converted Access database application

D

Dennis

Converted a database from Access '97 to 2002. Conversion
went flawlessly (no errors generated). Now when a certain
buttion is clicked (on a database lookup to a SQL
backend), the following error is generated:

Run-time error '13';

Type Mismatch

The code fragment generating this is:

Private Sub btn_Download_Click()

Dim DB As Database
Dim MyData As Recordset
Dim MyQuery As QueryDef

Set DB = DBEngine.Workspaces(0).Databases(0)
'Set MyData = DB.OpenRecordset("tbl_Batch",
DB_OPEN_TABLE)
Set MyData = DB.OpenRecordset("qry_Batch",
dbOpenDynaset)
..
..
..

The error is generated in the last line above. As you can
see, at some earlier time, the line was added and an
earlier one commented-out. I've not a vB guy, so have no
real idea what the significance of the change was (or what
the issue might be with the NEW syntax).

Any advice you could provide would be deeply appreciated.

Thanks
 
J

John Nurick

Hi Dennis,

Since no one else has answered I'll jump in. It looks as if Access 2002
is interpreting MyData as an ADO recordset, while your code assumes it's
a DAO one. Disambiguate your declarations as below, or remove the ADO
reference from the VBA project.

Dim DB As DAO.Database
Dim MyData As DAO.Recordset
Dim MyQuery As DAO.QueryDef
 
D

Dennis

That seemed to correct the issue. THANK YOU!!

Dennis
-----Original Message-----
Hi Dennis,

Since no one else has answered I'll jump in. It looks as if Access 2002
is interpreting MyData as an ADO recordset, while your code assumes it's
a DAO one. Disambiguate your declarations as below, or remove the ADO
reference from the VBA project.

Dim DB As DAO.Database
Dim MyData As DAO.Recordset
Dim MyQuery As DAO.QueryDef

Converted a database from Access '97 to 2002. Conversion
went flawlessly (no errors generated). Now when a certain
buttion is clicked (on a database lookup to a SQL
backend), the following error is generated:

Run-time error '13';

Type Mismatch

The code fragment generating this is:

Private Sub btn_Download_Click()

Dim DB As Database
Dim MyData As Recordset
Dim MyQuery As QueryDef

Set DB = DBEngine.Workspaces(0).Databases(0)
'Set MyData = DB.OpenRecordset("tbl_Batch",
DB_OPEN_TABLE)
Set MyData = DB.OpenRecordset("qry_Batch",
dbOpenDynaset)
.
.
.

The error is generated in the last line above. As you can
see, at some earlier time, the line was added and an
earlier one commented-out. I've not a vB guy, so have no
real idea what the significance of the change was (or what
the issue might be with the NEW syntax).

Any advice you could provide would be deeply appreciated.

Thanks

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top