Results 1 to 4 of 4
  1. #1
    JMichael is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    7

    Run Append Query Through VBA

    I need to run an initial query which will have to go to one target table, and every time the query is run thereafter it will have to only yield new results not already on the target table. I have to enable users to run it by a click of a button. Some of the data is more than 100000 rows so it has to export through Excel. I can do it through a regular query but there is a problem running the apend query through the code I've developed so looking for options to automate the process. Here is my code:

    Private Sub Command94_Click()
    Dim strFile As String
    Dim objXL As Object


    Dim objWB As Object

    strFile = CurrentProject.Path & "\Test.xlsx"

    If Len(Dir(strFile)) > 0 Then
    Kill strFile
    End If

    DoCmd.TransferSpreadsheet acExport, 10, _
    "Query Update Test", CurrentProject.Path & "\Test.xlsx", True


    Set objXL = CreateObject("Excel.Application")
    objXL.Visible = True
    Set objWB = objXL.Workbooks.Open(strFile)

    objXL.UserControl = True
    Set objXL = Nothing

    strFile = CurrentProject.Path & "\Test.xlsx"
    MsgBox "Data export completed", vbInformation, "Completed"
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Ive never had a problem running an append query thru code:

    docmd.openquery "qaApdQry"

  3. #3
    JMichael is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    7
    Its the DoCmd Transferspreadsheet which wont export

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    you cant export append queries, only select.
    run append ,
    then export the select qry.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-02-2015, 08:44 AM
  2. Access can't append all the records in the append query
    By fluffyvampirekitten in forum Access
    Replies: 2
    Last Post: 08-27-2015, 01:53 AM
  3. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  4. Replies: 7
    Last Post: 07-21-2011, 01:01 PM
  5. Append query won't append
    By yelkenli in forum Queries
    Replies: 5
    Last Post: 02-12-2010, 11:19 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