How to add a record using DAO in an Access Project

  • Thread starter Gman063 via AccessMonster.com
  • Start date
G

Gman063 via AccessMonster.com

I am new to using SQL server as the backend for my database and I am looking
form some help on a DAO add record procedure. I use this procedure allot on
Access DBs but now I have inherited an Access project and need a little help.
I am trying to use the following procedure to add a record to a table:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(“dbo.tblTableNameâ€)

With rs
.AddNew
!Field1 = txtField1
!Field2 = txtField2
.Update
End With
rs.Close
db.Close

This works great in an Access Database but not in the Project. I get the
following error when I try to run the above procedure:
“Runtime error ‘91’;
Object variable or With block variable not setâ€

Any help would be greatly appreciated.

Thanks in advance
 
S

Stefan Hoffmann

hi,
I use this procedure allot on
Access DBs but now I have inherited an Access project and need a little help.
I am trying to use the following procedure to add a record to a table:
Dim db As DAO.Database
Don't use DAO in an .adp, use ADODB instead.
This works great in an Access Database but not in the Project. I get the
following error when I try to run the above procedure:
“Runtime error ‘91’;
Object variable or With block variable not setâ€
The DAO library is not referenced by default in an .adp.



mfG
--> stefan <--
 

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