With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.
Public Function EMailTest() Dim db As DAO.Database Dim MailList As DAO.Recordset Dim MyOutlook As Outlook.Application Dim MyMail As Outlook.MailItem Dim Subjectline As String Dim BodyFile As String Dim fso As FileSystemObject Dim MyBody As TextStream 'Dim MyNewBodyText As TextStream Dim MyBodyText As String Set fso = New FileSystemObject Subjectline$ = "Email Test" BodyFile$ = "C:\TestEmail.txt" 'Checks to see if body file is there If fso.FileExists(BodyFile$) = False Then MsgBox "The body file isn??t where you say it is. " & vbNewLine & vbNewLine & _ "Quitting...", vbCritical, "I Ain??t Got No-Body!" Exit Function End If 'Since we got a file, we can open it up. Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault) 'and read it into a variable. MyBodyText = MyBody.ReadAll 'and close the file. MyBody.Close MyNewBodyText = MyBodyText ' Now we can replace tokens to our heart's content without worrying about corrupting the "master" template MyNewBodyText = Replace(MyNewBodyText, "[[FirstName]]", MailList("FirstName")) MyNewBodyText = Replace(MyNewBodyText, "[[GuestCount]]", MailList("GuestCount")) 'Now, we open Outlook for our own device.. Set MyOutlook = New Outlook.Application 'Set up the database and query connections Set db = CurrentDb() Set MailList = db.OpenRecordset("qryTestEmail-MoreThan30") 'now, this is the meat and potatoes. 'this is where we loop through our list of addresses, 'adding them to e-mails and sending them. Do Until MailList.EOF 'This creates the e-mail Set MyMail = MyOutlook.CreateItem(olMailItem) 'This addresses it MyMail.To = MailList("Email") 'This gives it a subject MyMail.Subject = Subjectline$ 'This gives it the body MyMail.Body = MyNewBodyText 'This sends it! MyMail.Send 'And on to the next one... MailList.MoveNext Loop 'Cleanup after ourselves Set MyMail = Nothing Set MyOutlook = Nothing MailList.Close Set MailList = Nothing db.Close Set db = Nothing End Function
Join the community of 500,000 technology professionals and ask your questions.