after delete export

arcootje

Board Regular
Joined
Jun 2, 2004
Messages
110
i've got a database with a query that combines several tables.
i want a macro or a module what makes the folowing automatacly:
msgbox: "are you sure that you want to export to sales.xls?
first delete file: sales.xls
export query sales to sales.xls
mail sales.xls

can anybody help me??
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi arcootje,

Following code might help. Please change the 3 variables as you need, file path & name, query name and email address.
It doesn't have a delete routine since it will overwrite the existing file automatically.


Code:
Sub ExportFile()
Dim objxls As Object
Dim objwrk As Object
Dim strFileName As String
Dim strQuery As String
Dim strEmailAddress as String

  If MsgBox("Are you sure that you want to export to sales.xls?", _
                            vbQuestion + vbYesNo) = vbNo Then Exit Sub
  
  '*****CHANGE THESE PARAMETERS*****
  strFileName = "C:\sales.xls"
  strQuery = "MyQueryName"
  strEmailAddress = "someone@email.com"
  '*********************************
  
  DoCmd.TransferSpreadsheet acExport, _
                            acSpreadsheetTypeExcel9, _
                            strQuery, _
                            strFileName
  
  'Send email by using Excel SendMail method.
  Set objxls = CreateObject("Excel.Application")
  Set objwrk = objxls.workbooks.Open(strFileName)
  objwrk.SendMail strEmailAddress , strFileName 'You can put a subject instead using strFileName here
  objwrk.Close False
  objxls.Quit: Set objxls = Nothing
End Sub

I hope it helps.
Suat
 
Upvote 0

Forum statistics

Threads
1,221,844
Messages
6,162,346
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top