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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send multi emails from outlook

Status
Not open for further replies.

officemanager2

Technical User
Oct 11, 2007
116
CA
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?

 
I should have pointed out the error message occurs with these two lines

Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.Application
 
You need to add a reference to Microsoft Access nn.n Object Library
In my case 12.0; your option may vary.

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Right now I have 'Microsoft Access 9.0 Object Library' checked. The access version is 2000. Still encountering the same problem.
 
Just realized the second line (from the lines the error is coming from) should read:


Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem

Fixed it but still getting the error.



 
Another thing to add:

The following are checked in the module references

Visual Basic For Applications
Microsoft Access 9.0 Object Library 5.3
OLE Automation
Microsoft Scripting Runtime
Microsoft DAO 3.6 Object LIbrary
Microsoft ActiveX Data Objects 2.1 Library
Microsoft Visual Basic for Applications Extensibility
 
Ok Found the answer! I did not have Outlook checked in the references!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top