dbTalk Databases Forums  

newbie needs examples of creating a recordset and inserting datausing it in Access 2007?

comp.databases.ms-access comp.databases.ms-access


Discuss newbie needs examples of creating a recordset and inserting datausing it in Access 2007? in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
r
 
Posts: n/a

Default newbie needs examples of creating a recordset and inserting datausing it in Access 2007? - 05-30-2010 , 09:28 PM






I have created a Access 2007 database, Test.mdb, created a table called
"mytest" and created required fields in it. Now, using VBA(Visual Basic
for Applications) I want to insert data into it using a Recordset from a
Word document.

Can anyone please point me to a proper link where there is an example of
how data is inserted using a Recordset into a Access 2007 table?

I created one using resources on Web, but it is not correct.

Sub TestRecordsetexample

Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1

myRecordSet.Open "[Test]"

Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1

myRecordSet.Open “SELECT * FROM mytest”

MsgBox myRecordSet.fields(0).value

myRecordSet.Close
cnn1.Close

End Sub

I get a compile time error for "Dim cnn1 As ADODB.Connection" as "User
defined Type not defined"


I want to choose Tools->References from the VBA Editor menu bar, but
References is disabled and I cannot choose it.

I guess I have to set up the connection from Word 2007(where the above
code is present as a Macro) to Access 2007(where the database is) which
I have not done.

Any advice would be welcome on how to fix the above error and some
examples of using Recordsets with Access 2007.

Thanks

Reply With Quote
  #2  
Old   
Keven Denen
 
Posts: n/a

Default Re: newbie needs examples of creating a recordset and inserting datausing it in Access 2007? - 05-31-2010 , 10:19 PM






On May 30, 8:28*pm, r <r...@r.com> wrote:
Quote:
I have created a Access 2007 database, Test.mdb, created a table called
"mytest" and created required fields in it. Now, using VBA(Visual Basic
for Applications) I want to insert data into it using a Recordset from a
Word document.

Can anyone please point me to a proper link where there is an example of
how data is inserted using a Recordset into a Access 2007 table?

I created one using resources on Web, but it is not correct.

Sub TestRecordsetexample

Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1

myRecordSet.Open "[Test]"

Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1

myRecordSet.Open “SELECT * FROM mytest”

MsgBox myRecordSet.fields(0).value

myRecordSet.Close
cnn1.Close

End Sub

I get a compile time error for "Dim cnn1 As ADODB.Connection" as "User
defined Type not defined"

I want to choose Tools->References from the VBA Editor menu bar, but
References is disabled and I cannot choose it.

I guess I have to set up the connection from Word 2007(where the above
code is present as a Macro) to Access 2007(where the database is) which
I have not done.

Any advice would be welcome on how to fix the above error and some
examples of using Recordsets with Access 2007.

Thanks
You need to add a reference to ADO before you can use it. If you
insist on using ADO, you need to figure out why you can't get into
your references. An alternate solution might be to think about using
DAO as it is native to Access.

Keven

Reply With Quote
  #3  
Old   
r
 
Posts: n/a

Default Re: newbie needs examples of creating a recordset and inserting datausing it in Access 2007? - 06-01-2010 , 08:14 AM



On 5/31/2010 11:19 PM, Keven Denen wrote:

Quote:
Thanks

You need to add a reference to ADO before you can use it. If you
insist on using ADO, you need to figure out why you can't get into
your references. An alternate solution might be to think about using
DAO as it is native to Access.

Keven
Thanks, that got fixed, but now i face another error
http://groups.google.com/group/comp....cec635e5cc78a#

Reply With Quote
  #4  
Old   
r
 
Posts: n/a

Default Re: newbie needs examples of creating a recordset and inserting datausing it in Access 2007? - 06-01-2010 , 08:17 AM



On 6/1/2010 9:14 AM, r wrote:
Quote:
On 5/31/2010 11:19 PM, Keven Denen wrote:


Thanks

You need to add a reference to ADO before you can use it. If you
insist on using ADO, you need to figure out why you can't get into
your references. An alternate solution might be to think about using
DAO as it is native to Access.

Keven
Thanks, that got fixed, but now i face another error
http://groups.google.com/group/comp....cec635e5cc78a#

Should clarify, the error of error of "Dim cnn1 As ADODB.Connection" as
User defined Type not defined" got fixed, but the error at

http://groups.google.com/group/comp....cec635e5cc78a#
is still present.

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.