dim db as database

J

John Kozma

I'm fairly familiar with tables, queries, forms and reports in MS Access,
having taught a couple of classes on the subject, but now I've got a job
writing vb code for forms. I did some minor fixes on code written for an
access 2.0 project, and it converted and compiled okay in Access 2000
(version 9). However, when I tried to redesign the database from scratch,
(in part a learning project for me), I'm unable to use a recordset object.
I tried the following code:

Dim db as database 'or DATABASE or Database
Set db = DBEngine.workspaces(0).databases(0) 'or CurrentDB

so I could use the OpenRecordset method of the database object. When the
set statement executes, however, I get a type mismatch error. The same
statements are included in the code that I converted from version 2 to
version 9, but do not produce the error. The converted project includes a
util (?) module of (to me) unknown origin containing oddly named objects
that are not available for viewing. I haven't tried importing that module
into my new project, but that seems like a horrible kludge anyway (if indeed
that's even related to the problem). There must be something simpler I'm
missing. Any suggestions would be most appreciated.

John Kozma
 
D

Duane Hookom

You must set a reference to DAO in your VBE. Select Tools|References and
find the Microsoft DAO library and check it.

You should always use code like:
Dim db As DAO.Database
Dim rs As DAO.Recordset
 
J

John Kozma

Thanks. I'll have to wait till Monday to try your suggestion, though,
'cause I only have version 8 of Access at home. I can't find anything
analogous to setting a reference in ver. 8, so I guess it's done
automatically. At least, I'm able to declare and initialize a database
object without getting the type mismatch error I get using version 9 at
work.

John Kozma
 
D

Douglas J. Steele

Database is a DAO object. Access 8 (better known as Access 97) uses DAO, but
by default Access 9 (Access 2000) uses ADO. In other words, you don't need
to set any other references in Access 97, because the reference is already
there.
 
M

Mike

I was having an almost identical problem as I'm a recent
convert to Access 2000 from 97. The answer helped me as
far as I can declare a database now, but where are the
balloon object declarations? I still cannot dim as
balloon.

Your help is appreciated

Mike
 

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