-
Recordsets, add new, DAO and ADO
I'm new to Access programming and am getting very confused. Hopefully, this is a basic query and will be easy to sort for all you experts!
WHAT I'M TRYING TO DO
I have an unbound form where I can enter upto 20 different lines of data (several fields for each line). What I want to do is add each completed line as an individual new record in "tblActions."
PROBLEM USING DAO
From what I've read, this seems an easier way to code than ADO, but I don't seem to have any references to DAO at all on my copy of Access (I'm using Access 2002 SP-2).
If, for instance, I type in:
Dim db As DAO.Database or Dim db as Database
Set db = CurrentDb
Then not only do I not get these appearing in the builder thing in the VB Editor, I also get an error message when I run the procedure "User specified type not defined" or something similar.
Is there some option or something I am supposed to tick to get VB to recognise DAO?
PROBLEM USING ADO
If I try using ADO, I get a different problem.
For the following code:
Dim conn As ADODB.Connection
Dim rec As ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = CurrentProject.Connection
rec.Open "tblActions", conn, adOpenDynamic, adLockBatchOptimistic, adCmdTable
I get run time error 91 "Object variable not set" on the last line of the code (rec.open). I also tried this by combining lines 3 and 4 into:
set conn=currentproject.connection (because I'm working in the same database so this seems more logical to me)
But I get the same error message.
Can anyone please tell me where I am going wrong on either DAO or ADO (or preferably both)?
-
When trying DAO, under 'Tools' and then 'References', do you have 'Microsoft DAO 3.6 Object Library' checked? Your version might be different than mine, but a DAO Object Library reference needs to be checked.
Using ADO, I don't see a
Set rec = New ADODB.recordset
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules