Results 1 to 4 of 4
  1. #1
    raynman1972 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    31

    Insert Pass-Through Results into Access Table with VB

    I have a pass-through query in some VB script that works fine and returns the correct data. I have searched the web for some code that could shed some light on how to take these results and insert them into an existing Access table using VB, but no luck. How can I make this work?



    Code:
    Private Sub RunPassThrough()
    
    Dim qdfPassThrough As DAO.QueryDef, MyDB As Database
    Dim strConnect, strSQL As String
    
    strSQL = "BLAH"
    
    If Not IsNull(CurrentDb.QueryDefs("qrySQLPass").SQL) Then 'doesn't exist
    CurrentDb.QueryDefs.Delete "qrySQLPass"
    End If
    
    Set MyDB = CurrentDb()
    
    Set qdfPassThrough = MyDB.CreateQueryDef("qrySQLPass")
    
    strConnect = "BLAH;"
    
    qdfPassThrough.Connect = "ODBC;" & strConnect
    qdfPassThrough.SQL = strSQL
    qdfPassThrough.ReturnsRecords = True
    qdfPassThrough.Close
    
    Application.RefreshDatabaseWindow
    
    DoCmd.OpenQuery "qrySQLPass", acViewNormal, acReadOnly
    DoCmd.Maximize

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I would recommend building your pass through query like you have done. Then if you want to append those records to an existing table, use the pass-through query in an Append Query to write them to your table. Append queries are pretty easy to run in VBA. If you aren't sure of the syntax, a good way is to create a Macro to run (open) the Append Query, save the Macro, and then use the "Convert Macros to Visual Basic" to convert the macro to VBA code.

  3. #3
    raynman1972 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    31
    That was almost too easy! And I got to try my hand at the whole Macro's piece for the first time. Thanks a bunch.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Your welcome. Glad it worked out for you.

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

Similar Threads

  1. Replies: 2
    Last Post: 06-25-2012, 09:24 AM
  2. Replies: 8
    Last Post: 03-21-2012, 09:39 AM
  3. Insert/update value of Access Table via UDP
    By Yance in forum Programming
    Replies: 1
    Last Post: 03-21-2011, 06:57 PM
  4. Replies: 2
    Last Post: 12-22-2010, 01:46 PM
  5. Replies: 0
    Last Post: 02-24-2010, 12:56 AM

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