Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2004, 01:12 AM
Authorized User
 
Join Date: Aug 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting A Record Set

Hey Guys,

Is there any way to insert a recordset from vba into an access table without doing it one insert at a time? This is how I am doing it now:

While Not rsData.EOF
 strqry = " insert into " & TableName & "(Telephone, Marked) " & _
          " values ('" & rsData("Telephone") & "'," & _
          " " & rsDataMarked") & ")"

        rsAction.Open (strqry)

        rsData.MoveNext
wend

//rsData is my record set that contains my data.

I want to do something like this:
strqry = " insert into tbl_ImportedList (Telephone)" & _
         " select tbl_txtFormat.phone" & _
         " FROM tbl_txtFormat"

         rsInsert.Open (strqry)

In this query, I am inserting everything from table tbl_txtFormat into table tbl_ImportedList in one shot without a loop. Is it possible to insert an entire recordset into a table with one query (ie. without a loop)? The way my code is now takes too long to process looping through insert statement after insert statement. Any information will really help me out. I have been wrestling with this for some time now.

Thanks,

Ryan




nikotromus
__________________
nikotromus
 
Old September 14th, 2004, 10:42 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

ryan
try this:

INSERT INTO tbl_ImportedList ( Telephone, Marked )
SELECT tbl_txtFormat.phone, tbl_txtFormat.marked
FROM tbl_txtFormat LEFT JOIN tbl_ImportedList ON tbl_txtFormat.ID = tbl_ImportedList.ID
ORDER BY tbl_txtFormat.ID;

john

 
Old September 14th, 2004, 11:54 AM
Authorized User
 
Join Date: Aug 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

John,

You listed the code to insert from one table to another. I need the code to insert from a recordset into a table.

Ryan


nikotromus
 
Old September 14th, 2004, 01:23 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ryan,
Iam using an event function -> lostfocus in Access Forms,
that is similar to your situation. I have an Access database
where my datas are imported from the internet as .csv Excel file ext to a gl table. I also have another table called log with fields and values same the as gl table.

After successfully downloading Excel gl datas to Access gl table,
I reconcile/update via function lostfocus in the event properties of the form. Meaning the other fields from the gl table that matches to log table will update those fields from the log table.

The only thing odd is I do it in access form manually, select the field with this function then click next record button.
I just havn't finished doing all this automatically.

Let me know if this recordset code is what you wanted.

john





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Inserting new record with detailsview gsrai31 ASP.NET 2.0 Basics 0 November 23rd, 2008 06:29 PM
problem inserting a record with autonumber phytos VS.NET 2002/2003 2 January 16th, 2006 07:14 PM
Checking a Database before Inserting a Record vbmazza VB Databases Basics 2 April 28th, 2005 07:23 AM
Select record after inserting it whyulil Classic ASP Databases 13 April 26th, 2004 06:05 AM
Inserting a Record and sending an email ambirC Classic ASP Databases 2 October 30th, 2003 07:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.