officemanager2
Technical User
Hi there: Got this code for sending multiple emails from access (Jeff Knapp is the original author).
Public Sub MassEmail()
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.Application
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Set fso = New FileSystemObject
'Create Subject line
Subjectline$ = InputBox$("Please enter the subject line for this mailing.")
'Input body text or document
BodyFile$ = InputBox$("Please enter the filename of the body of the message.")
'Open Outlook
Set MyOutlook = New Outlook.Application
'Set up the database query connections
Set db = CurrentDb()
Set MailList = db.OpenRecordset("emailall")
Set MyMail = MyOutlook.CreateItem(olMailItem)
Do Until MailList.EOF
MyMail.Bcc = MailList("emailaddress")
MailList.MoveNext
MyMail.Display
Loop
Set MyMail = Nothing
MyOutlook.Quit
MailList.Close
Set MailList = Nothing
End Sub
The problem is I keep getting the error "Compile Error 'user-defined type not defined'". Not sure why as I believe I followed all instructions. Looking at different boards some issues may be a conflict between Private/Public, but currently everything is public and not private.
Any suggestions?
Public Sub MassEmail()
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.Application
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Set fso = New FileSystemObject
'Create Subject line
Subjectline$ = InputBox$("Please enter the subject line for this mailing.")
'Input body text or document
BodyFile$ = InputBox$("Please enter the filename of the body of the message.")
'Open Outlook
Set MyOutlook = New Outlook.Application
'Set up the database query connections
Set db = CurrentDb()
Set MailList = db.OpenRecordset("emailall")
Set MyMail = MyOutlook.CreateItem(olMailItem)
Do Until MailList.EOF
MyMail.Bcc = MailList("emailaddress")
MailList.MoveNext
MyMail.Display
Loop
Set MyMail = Nothing
MyOutlook.Quit
MailList.Close
Set MailList = Nothing
End Sub
The problem is I keep getting the error "Compile Error 'user-defined type not defined'". Not sure why as I believe I followed all instructions. Looking at different boards some issues may be a conflict between Private/Public, but currently everything is public and not private.
Any suggestions?