Share via

Conditionally Export Access Table to Excel

Anonymous
2024-06-24T14:55:07+00:00

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.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2024-06-25T11:58:14+00:00

In which row in the table should the value at the Updates column position be >10?  Or are the Updates values in every row in the table the same?  If the latter then the table should be decomposed, with the Updates value being in a single row in a referenced table.  This removes the risk of update anomalies.

Either way you will probably need to call the DLookup function to get the value.  Do this in an If….End If construct, in which the export to Excel is conditional on the return value of the function being >10.

To export a table to Excel in VBA the TransferSpreadsheet method of the DoCmd object is used.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. George Hepworth 22,855 Reputation points Volunteer Moderator
    2024-06-24T19:04:41+00:00

    Yes, this is possible. How? Ah, the details derived from a high-level overview....

    It might involve a conditional similar to this:

    If tblYourTableNameGoesHere.Updates >10 THEN
    
      ...Code to export the table to Excel
    
    End If
    

    Put those lines in the procedure after the other code runs. I see you mention a macro, which I'd recommend you convert to VBA for this, and other purposes, anyway. Macros are fine for simplistic processes, but more serious work requires the greater power and flexibility of VBA.

    Was this answer helpful?

    0 comments No comments