Results 1 to 5 of 5
  1. #1
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171

    Append query does not work

    I have a situation whher a series of queries work fine when executed individually. However, when put together in a code sequence the append does not work.
    The following code is what I am doing:

    Private Sub BtnOIG_Click()
    'Import Monthly OIG Spreadsheet
    DoCmd.SetWarnings False
    DoCmd.RunSavedImportExport "Import-SoinMonthlyOIGDownload"

    'Determine new volunteers
    DoCmd.OpenQuery "QselMonthlyOIG"
    DoCmd.OpenQuery "QselNewMonthlyOIG" 'Unmatched records with TblPermOIG"

    'Add new OIG to TblPermOIG
    DoCmd.OpenQuery "QappNewOIGToPermOIG"

    'Prepare OIG for export to Excel
    DoCmd.OpenQuery "QdelTblTempOIG"
    DoCmd.OpenQuery "QselNewMonthlyOIGForExcel" 'Selecing required fields'
    DoCmd.OpenQuery "QappNewOIGToTblTempOIG" 'Table has required names for Export'
    DoCmd.RunSavedImportExport "Export-Soin_MonthlyOIG"
    DoCmd.SetWarnings True

    'Close all Queries


    DoCmd.Close acQuery, "QselMonthlyOIG"
    DoCmd.Close acQuery, "QappNewOIGToPermOIG"
    DoCmd.Close acQuery, "QappNewOIGToTblTempOIG"
    DoCmd.Close acQuery, "QdelTblTempOIG"
    DoCmd.Close acQuery, "QselNewMonthlyOIGForExcel"
    MsgBox "Monthly OIG has been exported to Excel"
    DoCmd.Close acQuery, "QselNewMonthlyOIG"
    DoCmd.Close
    DoCmd.OpenForm "Volunteer Menu"
    End Sub

    Everything works properly when executed one step at a time.
    The append that does not work when executed via code is DoCmd.OpenQuery "QappNewOIGToTblTemoOIG

    Any thoughts would be appreciated

    Thanks

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You could export the query "QselNewMonthlyOIGForExcel" and bypass the need for doing the append query, if all that you require is different column names for Excel.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Could be a timing issue.
    I can't tell which are Select queries and which are Action queries, but maybe try this:
    Code:
    Private Sub BtnOIG_Click()
        Dim d As dao.Database
    
        Set d = CurrentDb
    
        'Import Monthly OIG Spreadsheet
        DoCmd.RunSavedImportExport "Import-SoinMonthlyOIGDownload"
    
        'Determine new volunteers
        d.Execute "QselMonthlyOIG"
        d.Execute "QselNewMonthlyOIG"    'Unmatched records with TblPermOIG"
    
        'Add new OIG to TblPermOIG
        d.Execute "QappNewOIGToPermOIG"
    
        'Prepare OIG for export to Excel
        d.Execute "QdelTblTempOIG"
        
        DoEvents     '<<--
        
        d.Execute "QselNewMonthlyOIGForExcel"    'Selecing required fields'
        d.Execute "QappNewOIGToTblTempOIG"    'Table has required names for Export'
        DoCmd.RunSavedImportExport "Export-Soin_MonthlyOIG"
    
        MsgBox "Monthly OIG has been exported to Excel"
    
        DoCmd.Close
        DoCmd.OpenForm "Volunteer Menu"
    
    End Sub

  4. #4
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    aytee111, If I exported the Query, how do I get the headings changed?

    ssanfu, I am not familiar with the d.Execute commands.
    Qsel is a select query, Qapp is an append and Qdel is a delete Query

    Thanks

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In your query you can give any name that you want to for any field. If the field is called "CustAddr" for instance, the syntax in the query field is :
    Customer Address: [CustAddr]

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

Similar Threads

  1. Replies: 4
    Last Post: 12-06-2014, 08:49 PM
  2. Append doesn't work properly
    By fluppe in forum Access
    Replies: 3
    Last Post: 10-17-2014, 12:50 AM
  3. Replies: 3
    Last Post: 09-21-2013, 09:56 PM
  4. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  5. Replies: 7
    Last Post: 07-21-2011, 01:01 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