CurrentDb will not work

G

George M

I am building an application in access2000 as an adp
connected to SQL server 7. In trying to open a record set
in a module I can not get it to work like I have done many
times before in an mdb file, should I be doing something
different?
Code is;
Dim dbs As Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblStaff")
It compiles fine but at run time the "Set rst" line
produces an error "Object Variable or with block variable
not set", hover the mouse over the "Set dbs" statement
says it is still set to Nothing.
Same error with or without a DAO in front of Recordset.
Reference is set to the DAO 3.6 library.

Any guidance would be very much appreciated.
Thanks
George.
 
N

Nikos Yannacopoulos

George,

You need to declare dbs as a DAO database object:

Dim dbs As DAO.Database

Also, you may need to add parentheses at the end of its Set statement:

Set dbs = CurrentDb()

I believe this will solve your problem.

HTH,
Nikos
 
V

Van T. Dinh

There is no CurrentDB in an ADP.

In fact, if you use ADP, you really should be using ADO
coding rather than DAO.

Check Access VB Help on ADO Recordset.

HTH
Van T. Dinh
MVP (Access)
 
B

Brendan Reynolds

CurrentDb returns a reference to the current Jet database. In an ADP, there
is no current Jet database, and so CurrentDb returns Nothing.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
G

Guest

Many Thanks, doing the full ADODB did the trick.
-----Original Message-----
George,

You need to declare dbs as a DAO database object:

Dim dbs As DAO.Database

Also, you may need to add parentheses at the end of its Set statement:

Set dbs = CurrentDb()

I believe this will solve your problem.

HTH,
Nikos




.
 

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