Code to export my query as XLS to same directory each week.

  • Thread starter cw via AccessMonster.com
  • Start date
C

cw via AccessMonster.com

I have the following query: qryEquipment_Intelebill
- which I output as an Excel file
- save to a shared folder
- email the link to a co-worker
- first Monday of every week

How do I make this process completely automatic?..

- On Monday morning have the database open,
- run the query & save as Excel 2003~2007
- to my shared folder & always overwrite the old file
- then forward a LINK to that file only, in the Body of the email to the same
co-worker

I have worked with parts of this kind of procedure before but a little
unclear on putting it all together in a single unattended process.

Currently, I use a command button with this code behind it, then I email the
file while in Excel:
----------------------------------------------
Private Sub Command17_Click()
On Error GoTo Err_Handler
DoCmd.OutputTo acOutputQuery, "qryEquipment_Intelebill", acFormatXLS, "",
True
Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub
End Sub
 
C

CTomac

I have the following query: qryEquipment_Intelebill
- which I output as an Excel file
- save to a shared folder
- email the link to a co-worker
- first Monday of every week

How do I make this process completely automatic?..

- On Monday morning have the database open,
- run the query & save as Excel 2003~2007
- to my shared folder & always overwrite the old file
- then forward a LINK to that file only, in the Body of the email to the same
co-worker

I have worked with parts of this kind of procedure before but a little
unclear on putting it all together in a single unattended process.

Currently, I use a command button with this code behind it, then I email the
file while in Excel:
----------------------------------------------
Private Sub Command17_Click()
On Error GoTo Err_Handler
DoCmd.OutputTo acOutputQuery, "qryEquipment_Intelebill", acFormatXLS, "",
True
Exit_Sub:
   Exit Sub
Err_Handler:
   If Err = 2501 Then
   Else
       MsgBox "Error " & Err.Number & "  " & Err.Description
   End If
   Resume Exit_Sub
End Sub
To auto-send the email, add this after you output to excel:

DoCmd.SendObject acSendNoObject, , , "[Your Recipient]", , ,
"[Subject]" , _
"[Link here], 0
 
J

jalexander via AccessMonster.com

Thanks for the help.
Question: How can I alter my code to always save the file to the same place?
I have the following query: qryEquipment_Intelebill
- which I output as an Excel file
[quoted text clipped - 35 lines]To auto-send the email, add this after you output to excel:

DoCmd.SendObject acSendNoObject, , , "[Your Recipient]", , ,
"[Subject]" , _
"[Link here], 0
 
C

CTomac

Thanks for the help.
Question: How can I alter my code to always save the file to the same place?
I have the following query: qryEquipment_Intelebill
- which I output as an Excel file
[quoted text clipped - 35 lines]To auto-send the email, add this after you output to excel:
DoCmd.SendObject acSendNoObject, , , "[Your Recipient]", , ,
"[Subject]" , _
        "[Link here], 0

DoCmd.OutputTo acOutputQuery, "qryEquipment_Intelebill", acFormatXLS,
"\\server\path\file.xls", True

**Use True (last argument here) if you want to open Excel and view the
file, False if you don't.
 
C

cw via AccessMonster.com

Thankyou!
I will try this again and then lastly see if I can get the code to run on a
schedule, every Monday morning at 8:00am.
cw
Thanks for the help.
Question: How can I alter my code to always save the file to the same place?
[quoted text clipped - 12 lines]
DoCmd.OutputTo acOutputQuery, "qryEquipment_Intelebill", acFormatXLS,
"\\server\path\file.xls", True

**Use True (last argument here) if you want to open Excel and view the
file, False if you don't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top