Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2024
    Posts
    5

    Conditionally Export Access Table to Excel With Specific Criteria

    Is it possible to automate the conditional export of an Access table to Excel if it meets specific criteria? I would like to export a final Access table to Excel only if the Updates field value is >10 after I run my macro. Otherwise, I do not want the table to be exported from Access to Excel. I am a beginner in Access and currently use a macro to export my final table to Excel. I'm unsure if code can be used to only export the table if it meets the above criteria or how to go about implementing the code.





  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Yes, it's possible. Use an If Then Else structure. The real trick is figuring out what event to put code into. Are users entering value into Updates field? If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Join Date
    Jun 2024
    Posts
    5

    Sample Database for Conditionally Export Access Table to Excel with Specific Criteria

    I have attached a sample database.

    In summary, I run an audit each day to see if any providers need to be added or removed to/from a specific DB2 table based upon criteria. I create summary tables with counts of how many providers are being added or deleted every day when I run the audit so that I can add the counts to a dashboard report. (Note: the report criteria have changed since I initially posted as I now need to extract all updates >0.) I only want to export the summary tables to Excel if they contain actual counts. If the table is empty, I don't want to export the table to Excel.

    In the sample database, I want the Updates_080Adds table to export, but I do not want the Updates_080Deletes table to be exported. Currently the Updates_080Deletes table exports with the header fields to Excel.
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I don't use macros, only VBA. However, both have an If Then Else structure. Whichever way you go, need code to look at tables to see if there are records to export. For each table, use DLookup() or DCount() for that.

    Shouldn't have to write summary data to tables. Build aggregate queries and export those.

    Could use a form with a button called Export. VBA could look like:
    Code:
    If DCount("*", "FinalTable080Adds") > 0 Then
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qryUpdates_080Adds", "C:\Users\sk3998\Desktop\Updates080Adds.xls"
    End If
    If DCount("*", "FinalTable080Deletes") > 0 Then
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qryUpdates_080Deletes", "C:\Users\sk3998\Desktop\Updates080Deletes.xls"
    End If
    Or use macro If Then action.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Join Date
    Jun 2024
    Posts
    5
    This helped a lot - thank you! I was able to add code to the macro and it successfully worked.

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

Similar Threads

  1. Replies: 4
    Last Post: 09-19-2016, 05:02 PM
  2. Replies: 3
    Last Post: 04-07-2016, 04:36 AM
  3. Replies: 1
    Last Post: 10-28-2013, 12:32 PM
  4. Export Access to Excel : from a specific row
    By ragsgold in forum Import/Export Data
    Replies: 4
    Last Post: 08-01-2012, 03:49 PM
  5. Export a value to specific Excel cell
    By gg80 in forum Import/Export Data
    Replies: 5
    Last Post: 07-23-2010, 01:58 PM

Tags for this Thread

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