Database Object Declaration

  • Thread starter Thread starter Michael R
  • Start date Start date
M

Michael R

I have the following code in a form's OnLoad:

Dim someData As Database

Dim allTransactions As Recordset
Dim allChecks As Recordset
Dim checkCriteria, paymentCriteria As String

It gives me this error:

"Compile Error

User-defined type not defined"

It highlights the "Dim someData As Database" line of code.

Is there any reason why Access wouldn't have a Database
type?
 
How would I change the code to work then? I'm not sure
what you mean by the fact I must reference DAO 3.51 or
3.6.
 
under TOOLS/References you can declare (Check mark) then
Microsoft DAO 3.6 Object Library.

One you have done that, change your declarations to the
following:

Dim someData As DAO.Database
Dim allTransactions As DAO.Recordset
Dim allChecks As DAO.Recordset

This should fix your issue.
 
I'm not sure
what you mean by the fact I must reference DAO 3.51 or
3.6.

See:

ACC2000: By Default, New Access Databases Do Not Include Reference to Microsoft
DAO Object Library
http://support.microsoft.com/default.aspx?scid=kb;en-us;225962

References That You Must Set When You Work with Microsoft Access
http://support.microsoft.com/default.aspx?scid=kb;en-us;197110

Then, disambiguate your data object variable types by explicitly typing them as
DAO objects:

Dim someData As DAO.Database 'Presently not needed, but later ...?
Dim allTransactions As DAO.Recordset
Dim allChecks As DAO.Recordset

'You must explicitly type each variable, or they will dim as Variant
Dim checkCriteria, paymentCriteria As String
Dim checkCriteria As String, paymentCriteria As String
 
Back
Top