Sending a table by email in a CSV file

S

Stephane

Hello,

I tried to use the send object function to export a table by email using csv
but it does not work.


I was wondering if someone did it using VBA ?

My table name is "Monthly Report" and I need to export all the data without
the columns headers.

Thanks

Stephane
 
Joined
Feb 12, 2009
Messages
2
Reaction score
0
You can try the code below. It exports the table to a file then creates and email
using Outlook. You may need to add a reference to the Microsoft Outlook 10.0 object Library to do this.



Dim olookApp As Object
Dim olookMsg As Object

Set olookApp = CreateObject("Outlook.Application")
Set olookMsg = olookApp.CreateItem(olMailItem)

DoCmd.TransferText acExportDelim, , "Monthly Report", "C:\myFile.csv", True

With olookMsg
.To = "(e-mail address removed)"
.Subject = "Subject: File"
.Body = "Please find attached file." & vbCrLf & vbCrLf
.Attachments.Add ("c:\myFile.csv")

.Send

End With

Set olookMsg = Nothing
Set olookApp = Nothing
 
S

Stephane

Thanks Alex for the reply.

I knew I can do that this way using functions but I was wondering if it is
possible to create a module that performs a send object functions but with a
CSV file.

Since we are generating 90 reports for customers by deleting the table,
appending data, sending it, etc. my concern is that if something goes wrong,
it might happen that a report will be sent to the wrong customer which is a
big issue in my industry.

The only workaround is to create separate folder for each report and having
90 differents macros so at least if the report is not generated, the customer
will receive the last month report instead of Jones ABC LLC company for
example.

Your module is very useful since it does 2 macros inside 1 module.

Thanks

Stephane
 

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