Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic E-Mail to Outlook

Status
Not open for further replies.

rpbenito

Programmer
Jun 13, 2001
63
US
Is there a way to code something so that it will email a report or a .doc file to someone?

Thanks for your help,
Patto
 
This function exports an Access report to a *.snp (snapshot)
and emails to all addies in the RECIPIENTS table

Function MailDaily()
Dim dbsThis As Database
Dim rstSel As Recordset
Dim rstRec As Recordset
Dim olApp As Outlook.Application
Dim olNameSpace As NameSpace
Dim olFolder
Dim olMail As MailItem

Set dbsThis = CurrentDb
Set rstRec = dbsThis.OpenRecordset("RECIPIENT")

'export report to snapshot
DoCmd.OutputTo acReport, "DAILY TIMELINE", "SnapshotFormat(*.snp)", "C:\DAILY VOLUME UTL.SNP", False, ""

'create a mail piece
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
olNameSpace.Session.Logon "profilename", "password"
Set olFolder = olNameSpace.GetDefaultFolder(olFolderOutbox)
Set olMail = olFolder.Items.Add("IPM.Message")
olMail.Subject = "Network Volume Utilization " & DATE - 1
olMail.Attachments.Add "C:\DAILY VOLUME UTL.SNP"
With rstRec
Do Until .EOF
olMail.Recipients.Add .Fields(0)
.MoveNext
Loop
End With
olMail.Recipients.ResolveAll
olMail.Send
'EOJ:
olApp.Session.Logoff
olApp.Quit
Set olApp = Nothing
End Function

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top