[AccessD] Insert Into 101

Max Wanadoo max.wanadoo at gmail.com
Mon Oct 12 08:52:38 CDT 2009


Here is a couple of examples, not sure if I understood you correctly though:

' Append record to the temp audit table.
  Set db = DBEngine(0)(0)
  sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser ) " &
_
         "SELECT 'Delete' AS Expr1, Now() AS Expr2, NetworkUserName() AS
Expr3, " & sTable & ".* " & _
         "FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " &
lngKeyValue & ");"
  db.Execute sSQL, dbFailOnError


sql = "INSERT INTO [MCMSelectionSingleTemp] (FKPersonID,AddrCode,Myas) " & _
          "SELECT QF_People.PersonID,QF_People.AddrCode, Myas" & _
        " FROM QF_People WHERE (QF_People.PersonStatus='Active') AND
QPersonID in (Select FKPersonID from mcmIncomeTransactions) ORDER BY
QF_People.AddrCode"


Max


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Collins, Darryl
Sent: 12 October 2009 03:55
To: Access Developers discussion and problem solving
Subject: [AccessD] Insert Into 101

Hi Folks,

I know I can do this

INSERT INTO tblMyTable
SELECT * FROM tblMyOtherTable

Is there any way of using SQL to select a recordset and then using that
RS in the insert statement?

    cnn.Open DbADOConStr
    Set rst = New ADODB.Recordset
    rst.CursorLocation = adUseClient
    rst.Open gstrSQL, cnn, adOpenForwardOnly, adLockReadOnly

    INSERT INTO tblMyTable
    SELECT * FROM  " & rst

I have a work-around for this already, but it involves looping and
cloning recordsets and jumping thru other hoops.  Frankly it seems very
inelegant and inefficent (even though it is fast enough for my
purposes).  I am sure there must be a way of getting a recordset for the
backend and just dumping the whole thing into a local table (assuming
all the fields line up ofcourse).

Cheers
Darryl

"This e-mail and any attachments to it (the "Communication") is, unless
otherwise stated, confidential,  may contain copyright material and is for
the use only of the intended recipient. If you receive the Communication in
error, please notify the sender immediately by return e-mail, delete the
Communication and the return e-mail, and do not read, copy, retransmit or
otherwise deal with it. Any views expressed in the Communication are those
of the individual sender only, unless expressly stated to be those of
Australia and New Zealand Banking Group Limited ABN 11 005 357 522, or any
of its related entities including ANZ National Bank Limited (together
"ANZ"). ANZ does not accept liability in connection with the integrity of or
errors in the Communication, computer virus, data corruption, interference
or delay arising from or in respect of the Communication."

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list