Results 1 to 2 of 2
  1. #1
    gimmy is offline Novice
    Windows 7 32bit Access 97
    Join Date
    Sep 2011
    Posts
    1

    append query

    Hi,
    I have to append to a table (1A) only the last record of the table (2A).



    I have written the following code but it doesn't work:

    Private Sub Comando1_Click()
    Dim db As Database
    Set db = CurrentDb
    Dim rst As Recordset

    Set rst = db.OpenRecordset("2B", dbOpenDynaset)
    rst.MoveLast
    nr = rst.RecordCount
    y = rst!CNT ' the CNT of the last record
    MsgBox y
    rst.Close
    db.Close

    Dim strSQLInsert As String
    strSQLInsert = "Insert Into 1A (CNT,CITY,ZIP) SELECT CNT,CITY,ZIP FROM 2B WHERE CNT = y "
    DoCmd.RunSQL strSQLInsert

    end sub

    If I use FROM 2B where cnt= 100" where 100 is the cnt of the last record everything is ok.
    How can I assign the values of CNT to y in the strSQLinsert?

    Can someone help me?
    My best regards,
    gimmy

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    strSQLInsert = "Insert Into 1A (CNT,CITY,ZIP) SELECT CNT,CITY,ZIP FROM 2B WHERE CNT = " & y
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-21-2011, 01:01 PM
  2. append query help
    By SlowPoke in forum Access
    Replies: 2
    Last Post: 09-25-2010, 10:47 AM
  3. Append query won't append
    By yelkenli in forum Queries
    Replies: 5
    Last Post: 02-12-2010, 11:19 AM
  4. Append Query
    By aabh in forum Queries
    Replies: 6
    Last Post: 02-02-2010, 04:26 PM
  5. Append Query
    By cotri in forum Queries
    Replies: 1
    Last Post: 01-28-2010, 08:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums