473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

E-mailing excel files from an access module

4
I use this code to create some excel files from my DB, I would like a process that will send each indivdual file to a specific e-amil address, I will hold the e-mais in a table linked to the fundgroup name. This is the code i use to create the excel files, can anyone help with the code to send these e-mails, I will be creating these files each month so also need to pass through the period through the code to ensure i pick up the correct months file to send.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command4_Click()
  2.  
  3.   Dim db As DAO.Database, rs As DAO.Recordset, str1Sql As QueryDef, strCrt As String, strDt As String
  4.   Set db = CurrentDb
  5.  
  6.   Set rs = db.OpenRecordset("SELECT distinct FundGroup FROM tbl_EFMMI_ReportFeeder ORDER By FundGroup;")
  7.   '**** fieldname, consider this to be how the records are grouped within the dataset.
  8.  
  9.   strDt = [Forms]![Form1]![Period]
  10.  
  11.   rs.MoveLast
  12.   rs.MoveFirst
  13.  
  14.   Do While Not rs.EOF
  15.  
  16.   strCrt = rs.Fields(0)
  17.  
  18.   Set str1Sql = db.CreateQueryDef("" & strCrt, "SELECT tbl_EFMMI_ReportFeeder.*  FROM tbl_EFMMI_ReportFeeder WHERE tbl_EFMMI_ReportFeeder.FundGroup = '" & strCrt & "';")
  19.  
  20.  
  21.   DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "" & strCrt, "C:\H\EFMMI\ " & strCrt & "_" & strDt & ".xls", True
  22.  
  23.   DoCmd.DeleteObject acQuery, "" & strCrt
  24.  
  25.   rs.MoveNext
  26.  
  27.   Loop
  28.  
  29.   rs.Close
  30.   Set rs = Nothing
  31.   Set db = Nothing
  32.  
  33.  
  34. End Sub
Oct 25 '11 #1
1 1287
patjones
931 Expert 512MB
Hi Piers,

The basic code that I use for emailing from VBA is the following:

Expand|Select|Wrap|Line Numbers
  1.     Dim olApp As New Outlook.Application, olMail As Outlook.MailItem
  2.     Set olMail = olApp.CreateItem(olMailItem)
  3.  
  4.     With olMail
  5.         .To = strSendTo
  6.         .Subject = strSubject
  7.         .ReadReceiptRequested = False
  8.         .Body = strBody
  9.         .Attachments.Add strAttachFile
  10.  
  11.         .Send
  12.     End With
  13.  
  14.     Set olApp = Nothing
  15.     Set olMail = Nothing

Here olMail is the object that represents the email that you're going to send, and the methods of this object correspond to various parameters that you're already familiar with from Outlook such as .To, .Subject, and so forth. The key method for you is .Attachments, which allows you to attach a file(s) to the message. Here, the variable strAttachFile holds the path to the file that you're sending.

You would want to implement this code after you have a file to actually send...namely after your TransferSpreadsheet call.

Let us know if this is helpful at all.

Pat
Oct 25 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Oci-One Kanubi | last post by:
Everything works fine in Access, but when I double-click on the resultant Excel files the first one opens correctly, but subsequent ones, and any other Excel files I try to open, fail to display at...
2
by: Jen | last post by:
Trying to take one table in access and split it into multiple excel files(using an excel template); and then email based on email addresses in Table2; Of course, I would like to do all of this...
0
by: Jack | last post by:
Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the...
17
by: Pam Ammond | last post by:
I need to use Microsoft Access Automation within a Visual Studio 2003 program written in C# for Windows Forms. When a button is clicked in my VS.NET program, I want it to run a Microsoft Access...
2
by: amy | last post by:
Hi, all: i am a new end user of access, now I have many excel files need to import to One table in access (combine all excel files into one table in excel). In excel files, some columns will have...
1
by: anthony.ting | last post by:
I've written a vba module that takes several .csv files and imports them all into access using a pre-defined specification. All is good if I set the spec up to import the following as text: ...
18
by: gonzlobo | last post by:
No, I don't want to destroy them (funny how the word 'decimate' has changed definition over the years) :). We have a data acquisition program that saves its output to Excel's ..xls format....
11
by: MD | last post by:
Hello, I need to import a sheet of 884 different excel-file with same lay- out. The sheet name is 'Totaal' and is the same in all different files. Is there a script (module) in order to: 1....
1
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
by: titli | last post by:
I have created the excel worksheet from MS Access using the following code: Dim xlApp As Excel.Application Dim xlWB As Excel.Workbook Set xlApp = New Excel.Application With xlApp ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.