Results 1 to 6 of 6
  1. #1
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    281

    Help Using a RecordSet With a Loop in a PassThrough Query

    Greetings All...

    I am currently using a recordset (Rs) to loop through a ListBox grab the selected items and add them to an Access BkEnd Linked Table

    What I am trying to do is use a pass through query to send the data directly to the SQL server.

    Here is the Rs that populates the access linked table
    Code:
    Dim Dbs As DAO.Database
    Dim Rs As DAO.Recordset
    Dim Item As Variant
    Set Dbs = CurrentDb()
    Set Rs = Dbs.OpenRecordset("TblTmpTktExtAccs")
       
      For Each Item In Me.List14.ItemsSelected
        Rs.AddNew
          Rs!ItemsRequested = List14.ItemData(Item)
        Rs.Update
      Next
      
        Rs.Close
      
      Set Rs = Nothing
    Below is a passthrough Query I am currently using with an INSERT Query
    Code:
    Dim conn As ADODB.Connection
    Set conn = New ADODB.Connection
    conn.ConnectionString = strConnection
    conn.Open
    
    StrSQL = "INSERT INTO dbo.SalesNos (EmpID, EmpName, SalesTtl) " & _
             "VALUES('" & EmpId & "', '" & EmpName & "', '" & Sales & "')"
    conn.Execute StrSQL
    
    conn.Close
    Set conn = Nothing
    What I'm trying to do is adopt the looping Rs to the passthrough or vice versa

    As Always - Thank You for your help...

  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
    If the SQL Server table is linked the same code will work. If you want to use the pass through, you'd put the bit setting strSQL and the Execute line inside the loop.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    281
    Hey Paul Thanks for being out there...

    Not sure I'm following, but that may be due to my not explaining myself very well

    Here is an 'in my mind - this seems like it should work' version of what I am trying to do
    Code:
    Dim conn As ADODB.Connection
    Dim Rs As DAO.RecordsetSet conn = New ADODB.Connection
    conn.ConnectionString = strConnection
    conn.Open
    
    Set Rs = conn.OpenRecordset("tri.TktExtAccsTmp")
       
      For Each Item In Me.List14.ItemsSelected
        Rs.AddNew
          Rs!ItemsRequested = List14.ItemData(Item)
        Rs.Update
      Next
      
      conn.Close
     Set conn = Nothing

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That's going a different direction. I assume it doesn't work? What's the error, and where? Based on your original question I was envisioning:

    Code:
      For Each Item In Me.List14.ItemsSelected
        StrSQL = "INSERT INTO dbo.SalesNos (EmpID, EmpName, SalesTtl) " & _
                  "VALUES('" & EmpId & "', '" & EmpName & "', '" & Sales & "')"
        conn.Execute StrSQL
      Next
    With the values coming from the listbox or wherever.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    281
    OMG!!! LOL!!!

    Your interpretation of what I wanted to do > my interpretation of what I wanted to do.

    That work's brilliantly, Paul!!

    Thank You so very much!!

    (stay tuned ((please)) for my next question)

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    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. Need your help in a loop in the recordset
    By Muntasser in forum Programming
    Replies: 3
    Last Post: 03-19-2018, 12:04 PM
  2. Loop Not Progressing Through Recordset
    By nmlinac in forum Programming
    Replies: 1
    Last Post: 02-15-2013, 10:54 AM
  3. Double loop recordset
    By silverspr in forum Programming
    Replies: 7
    Last Post: 03-07-2012, 01:43 PM
  4. Loop through recordset
    By eliedebs in forum Programming
    Replies: 1
    Last Post: 01-11-2012, 12:26 AM
  5. Cannot Make Table with Passthrough Query
    By chasemhi in forum Import/Export Data
    Replies: 0
    Last Post: 12-05-2011, 01:30 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