Exporting to Excel

  • Thread starter Thread starter Jennifer Sanders
  • Start date Start date
J

Jennifer Sanders

Is there a way to export selected fields of an Access DB
table to a regularly (and automatically) updating excel
sheet? We are an online DVD store and want to offer a
constantly-current excel download of product info and
pricing for wholesalers...
 
Hi Jennifer,

One basic approach would be:

1) create a query (or a report) that selects, formats and sorts the data
you want to export.

2) use VBA code running in Access to export this to Excel.

If you want the export to happen at regular intervals you could use the
Timer event on a form to trigger it. In pseudocode:

strTempFileSpec = "D:\folder\ProdInfo$$$.xls"
strFileSpec = "D:\folder\ProdInfo.xls"

If strTempFileSpec exists Then delete it
On Error Resume Next
DoCmd.TransferSpreadsheet to export query to strTempFileSpec
If Err.Number = > Then
'Something went wrong
Send an email to the administrator with the details
Exit Sub
End If
Do While strFileSpec exists 'delete previous version if needed
DoEvents 'let other processes go ahead
Kill strFileSpec
'check if any error and take appropriate action
'but if the file is in use by being downloaded,
'just go round the loop
Loop
On Error Goto 0
'Rename temp file to "real" name
Name strTempFileSpec As strFileSpec

Meanwhile the website code would have to be able to handle requests for
downloads that come in during the (short) period between the old version
being killed and the new one being renamed.

Another approach - preferable if the database is changing all the time -
would be to have the website code cause the database to export a fresh
Excel file for every downloard request. Access can do this but it's not
really designed for that sort of unattended work: see

Considerations for Server-Side Automation of Office:
http://support.microsoft.com/?id=257757
Using Microsoft Access as an Automation Server
http://support.microsoft.com/?id=147816
 
Back
Top