very basic question

B

Benoit

Hi,
I'm trying to write my first vba code that I want to use
to send email via access.
I've found a few example on how to do it... but I got
block at my first line of code. What's wrong in the
following statement:
==================
Private Sub Command0_Click()
Dim db As Database <<< I get "compile error: used-
defined type not defined"

Dim RS As Recordset
Dim strMsg As String
End Sub
==================
I'm calling this from a button on a form.
I'm using Access 2002

thanks
a very beginner
 
J

Joe Fallon

You have a problem with your references.
Also, A2000 sets a reference to ADO by default on any new database.
If you don't use it, then uncheck it and check DAO 3.6 instead.
 
G

Guest

I found out that when I type in the vb editor, database is
not in the list for value I can use after Dim As ??
Am I missing a package or something like that?
Note that Recordset is in the list.

thanks again
 
D

Dirk Goldgar

Benoit said:
Hi,
I'm trying to write my first vba code that I want to use
to send email via access.
I've found a few example on how to do it... but I got
block at my first line of code. What's wrong in the
following statement:
==================
Private Sub Command0_Click()
Dim db As Database <<< I get "compile error: used-
defined type not defined"

Dim RS As Recordset
Dim strMsg As String
End Sub
==================
I'm calling this from a button on a form.
I'm using Access 2002

thanks
a very beginner

Nothing's wrong, except that you need to set a reference to the
Microsoft DAO 3.6 Object Library. With your code window open on the
screen, click Tools -> References..., locate the reference in the list
of available references, and put a check mark in the box next to it.
Then do one of the following two things:

(a) Remove the check mark next to the reference to Microsoft ActiveX
Data Objects 2.x Library, or

(b) change these two lines:
Dim db As Database
Dim RS As Recordset

to

Dim db As DAO.Database
Dim RS As DAO.Recordset

One of these is needed because the ADO library has some objects with the
same names as the DAO library, and you don't want Access to be confused.
 
G

Guest

Hi again,

ok, I have found the following in help:
=====
The type is a valid type, but the object library or type
library in which it is defined isn't registered in Visual
Basic.
Display the References dialog box, and then select the
appropriate object library or type library. For example,
if you don't check the Data Access Object in the
References dialog box, types like Database, Recordset, and
TableDef aren't recognized and references to them in code
cause this error.
=====
so now my question is "how do I display the References
dialog box" ???/?
 
G

Guest

thanks a lot.
I was getting close. I was looking for the Data Access
reference as documented in the help.
Without your help I would have never found it.
It's working now.

thanks a lot.
Benoit
 

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