Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

declaring recordset

Status
Not open for further replies.

smsmarkvi

Programmer
Dec 23, 2002
6
US
I am tring to write a dbase in access that will import a text file into a table. I went to the m/s know. dbase and found a little script that will do exactly what I need.

ONE PROBLEM.

It is written for the Northwind dBase. I changed all of the variables to meet my needs...and it won't get be a centain line. It reads..

(Dim db As Database, rs As a Recordset... is in the beginning, it is fine)

Trouble spot...Set rs = db.OpenRecordset("TestImport", dbOpentable)

I get the "runtime error 13" type mismatch ??????

This same script works perfect in the Northwind Dbase, Just not in a "new" dbase....

What have I not turned on?

Scott

 
What variables does openrecordset need?

I think the dbopentable may not be correct but i'm not sure.

Transcend
[noevil]
 
Ah I think I have it,

in the new database do you have a reference to DAO 3.6?

Transcend
[noevil]
 
It is tring to open a table. Again, when I put this into the "Northwind" database...it works to a T. When I open a new dbase..I get that error...I also needed to go to the references dialog box and check a few things for the Dim db As Database to work
 
yes to DAO 3.6 ....that enabled the Set db As Database

No I have not tried the dbOpendynaset ....

with that why would the same script work in the Northwind Dbase and not a "new" dbase.

Scott
 
Have you made sure that in your reference you don't have ADO and DAO checked?
This can cause confusion

Transcend
 
Is there a line of code setting "db"?

Can you show it here?

 
If using A2K you may need to be more precise with your declarations, even if you have the DAO 3.6 library referenced.e.g.

Dim db As DAO.Database
Dim rs As DAO.Recordset

And as Falcon says you should have line somewhere along the lines of:

Set db = CurrentDb

HTH Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....
 
The rs = DAO.Recordset did the trick....

Ques: Why was it necessary? In the Northwind Dbase...the plain declairation worked. Being new, I won't argue with success! (w/in Access 2k, DAO was necessary...in VB 6.0, the original syntax would have worked?)

Thanks

Scott
 
The reasoning....

By default, Access 2K and newer uses ADo objects....they are defined in the references for every database you create. If you wish to use DAO objects in a database, you must explicitly go to the references and turn it on. In the reference list you have priorities....in other words, which group of objects should Access look in first for the object you are defining. In A2K and newer the ADO object set appears before the DAo object set in the priority list....

So if you want an ADO object, you only have to use:
Dim rst As Recordset
and you MUST use:
Dim rs As DAO.Recordset
for a DAO object.

It is also highly recommended if you use DAO objects to explicitly define the ADO objects also but it is not necessary:
Dim rst As ADODB.Recordset
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top