PC Review


Reply
Thread Tools Rate Thread

Can access DAO in Access 2003

 
 
=?Utf-8?B?UGF1bCBXYXJzaGF3c2t5?=
Guest
Posts: n/a
 
      1st Jun 2005
I'm having a strange problem. I have a database that was created in Access
2002, but I am now working with it in Access 2003. I'm trying to write code
that adds a record and then gets the primary key of the new record (which is
an autonumber). I found a post that should help me to do this, but it seems
that VBA does not have DAO loaded. The reason I suspect this is that the
following statements fail:

Dim rs as DAO.RecordSet
Dim db as DAO.Database
(Also fails if I use "Dim db as Database")

I am also unable to view DAO objects in the Object Browser. I get an error
that the object "is in the library 'DAO' which is not currently referenced".

BTW can anyone suggest an easier way to get the index than the following
snippet?

Dim rs As Recordset
Dim db As Database
Dim key as Integer

Set db = DBEngine(0)(0)
CurrentDb.Execute "INSERT INTO Residents (NameLast, NameFirst) VALUES ('" _
& GetLastName(NewData) & "' ,'" & GetFirstName(NewData) & "');"
Set rs = db.OpenRecordset '("SELECT @@IDENTITY AS LastID;")
key = rs!LastID

Thanks,

Paul Warhsawsky
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGF1bCBXYXJzaGF3c2t5?=
Guest
Posts: n/a
 
      1st Jun 2005
Silly me, just needed to add a reference to DAO 3.6. Sorry.

"Paul Warshawsky" wrote:

> I'm having a strange problem. I have a database that was created in Access
> 2002, but I am now working with it in Access 2003. I'm trying to write code
> that adds a record and then gets the primary key of the new record (which is
> an autonumber). I found a post that should help me to do this, but it seems
> that VBA does not have DAO loaded. The reason I suspect this is that the
> following statements fail:
>
> Dim rs as DAO.RecordSet
> Dim db as DAO.Database
> (Also fails if I use "Dim db as Database")
>
> I am also unable to view DAO objects in the Object Browser. I get an error
> that the object "is in the library 'DAO' which is not currently referenced".
>
> BTW can anyone suggest an easier way to get the index than the following
> snippet?
>
> Dim rs As Recordset
> Dim db As Database
> Dim key as Integer
>
> Set db = DBEngine(0)(0)
> CurrentDb.Execute "INSERT INTO Residents (NameLast, NameFirst) VALUES ('" _
> & GetLastName(NewData) & "' ,'" & GetFirstName(NewData) & "');"
> Set rs = db.OpenRecordset '("SELECT @@IDENTITY AS LastID;")
> key = rs!LastID
>
> Thanks,
>
> Paul Warhsawsky

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      1st Jun 2005
That's odd: Access 2003 has a reference to DAO 3.6 by default!

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Paul Warshawsky" <(E-Mail Removed)> wrote in
message news:C5C7C842-39B2-44C7-94F8-(E-Mail Removed)...
> Silly me, just needed to add a reference to DAO 3.6. Sorry.
>
> "Paul Warshawsky" wrote:
>
>> I'm having a strange problem. I have a database that was created in
>> Access
>> 2002, but I am now working with it in Access 2003. I'm trying to write
>> code
>> that adds a record and then gets the primary key of the new record (which
>> is
>> an autonumber). I found a post that should help me to do this, but it
>> seems
>> that VBA does not have DAO loaded. The reason I suspect this is that the
>> following statements fail:
>>
>> Dim rs as DAO.RecordSet
>> Dim db as DAO.Database
>> (Also fails if I use "Dim db as Database")
>>
>> I am also unable to view DAO objects in the Object Browser. I get an
>> error
>> that the object "is in the library 'DAO' which is not currently
>> referenced".
>>
>> BTW can anyone suggest an easier way to get the index than the following
>> snippet?
>>
>> Dim rs As Recordset
>> Dim db As Database
>> Dim key as Integer
>>
>> Set db = DBEngine(0)(0)
>> CurrentDb.Execute "INSERT INTO Residents (NameLast, NameFirst) VALUES ('"
>> _
>> & GetLastName(NewData) & "' ,'" & GetFirstName(NewData) & "');"
>> Set rs = db.OpenRecordset '("SELECT @@IDENTITY AS LastID;")
>> key = rs!LastID
>>
>> Thanks,
>>
>> Paul Warhsawsky



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't open my Access files after conversion from Access 97 to Access 2003 M Shafaat Microsoft Access 5 10th Apr 2010 09:04 PM
Executing Word 2003 Mailmerge from Access 2000 module running in Access 2003 ML Microsoft Access VBA Modules 3 25th Oct 2006 11:25 PM
Access 2003 Won't Update Pivot Tables Created in Access 2003 =?Utf-8?B?TWljaGFuaWtlcg==?= Microsoft Access 3 16th Oct 2006 08:25 AM
Saving Access 2007 database in Access 2003 format fails in Access =?Utf-8?B?U3Bpcm8=?= Microsoft Access External Data 0 13th Aug 2006 08:37 AM
Automate Saving Access 2003 to Access 2000 and Access 97 =?Utf-8?B?Q2hlcnls?= Microsoft Access VBA Modules 10 1st Oct 2005 08:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 PM.