Dim As Database

  • Thread starter Thread starter JHarris
  • Start date Start date
J

JHarris

Guest
Hello everybody,

I was hoping to get some feedback. I am using some VB code in Access 2000, trying to add a record to an existing table (ITEM) by using a DAO procedure. My problem is that when I declare my variable dbs as a Database, the Database isn't recognized...why...how do I fix it? The code is below:

Private Sub cmdItemAdd_Click()
On Error GoTo cmdItemAdd_Click_Err
Dim dbs As Database, rst As RecordSet
Set dbs = CuttentDB
Set rst = dbs.OpenRecordset("Item", dbOpenDynaset)
With rst
.AddNew
![Item_Serial] = txtHardSerial.value
:
:
:
.Update
End With
rst.Close
cmdItemAdd_Click_Exit:
Exit Sub
cmdItemAdd_Click_Err
MsgBox Err.Description
Resume cmdItemAdd_Exit
End Sub


Dim dbs AS Database, rst AS RecordSet is causing an error because the data type Database isn't recognized. Isn't this built in?
 
Try Dim dbs As DAO.Database

Because Acc2k and later use ADO by default, you have to explicitly tell Access what sort of Database variable this is (and make sure the DAO 3.6 Reference is checked in Tools>References, of course).

Alternatively you can look into using the ADO method for this.
 
You must make sure that the DAO object library is higher priority than the ADO library.
It will not work otherwise:D
 
Both DavidR and Nero are right.

Nero's answer is correct if you don't qualify the database as

Dim dbCur as DAO.Database.



DavidR's answer is correct if the references are in the wrong order and you don't want to change this order for some reason.
 
DAO vs. ADO Library

How do you set the DAO library higher than the ADO library?

Thanks in advance
 
DAO vs. ADO Library

How do you set the DAO library higher than the ADO library?

Thanks in advance
 

Users who are viewing this thread

Back
Top Bottom