BlueMeanie
May 12 2004, 08:26 AM
I have a table holding contact information. One Y/N field is a reference to whether a contact should recieve a monthly newsletter.
This is going to be done using a HTML email.
What I want is to automate the sending of all emails on the push of a button. I have automated email generation and sending before, but have not created a HTML text body through VBA before.
Does anybody have knowledge of this that could pass on?
Thanks
Paul
good_patriot
May 12 2004, 08:32 AM
The "SendObject" macro choice can perform this exact procedure. Under the "To" category you can list as many emal addresses as you want , they need only be seperated by semi-colons. It also allows for text messaging. When I use this I have to shut off a few system windows that pop up using the SetWarnings command.
BlueMeanie
May 12 2004, 08:49 AM
Thanks for the reply.
The issue is the HTML body text not the sending to multiple users.
To do the multiple sending I will loop through a recordset of the contacts that require the newsletter, this way the list can change from month to month without ever having to alter the code.
danishani
May 12 2004, 10:09 AM
Hi there,
I am bussy with this issue recently, so far I know u can attach an HTML document to your mail and it will show up automaticly in your body in Outlook or Groupwise if its configured right.
Another approach for attach HTML to body by code is something like this:
CODE
Set myOLApp = CreateObject("Outlook.Application")
Set myItem = myOLApp.CreateItem(olMailItem)
myItem.HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>"
'Item displays HTML message.
myItem.Display
U need to have Microsoft Outlook Object ticked to get this code working.
HTH
Daniel
BlueMeanie
May 13 2004, 03:43 AM
Thanks for the info Dani, I will give this a go sometime today.
Cheers
Paul
BlueMeanie
May 13 2004, 09:17 AM
Have created the code that i felt should work but have hit a snag.
I want to use a text file to hold the HTML as opposed to entering it via VBA. This is so the boss can just alter the text as he sees fit without going into the database internals.
To do this I thought the use of a pathname for the file would do the job, so I created a string variable and set it to contain the pathname. The string variable is then called.
In relation to your code this would be - myItem.HTMLBody = myVariable
I am getting a compile error on the specific line of code stating 'Object Required'
Why is this when I have previously declared the variable???
See code below if needed. Many Thanks
Paul
_________________________________________________
Private Sub cmd_SendNewsletter_Click()
Dim db As Database
Dim contactRec As Recordset
Dim objOutlook As New Outlook.Application
Dim objMessage As MailItem
Dim strBody As String 'Holds the mail body to be sent
Dim strName As String 'Holds the name of the recipient
Dim strHTML As String 'Holds the HTML text to be included in the body
'Set Database & Recordset objects
Set db = CurrentDb()
Set contactRec = db.OpenRecordset("tbl_Contacts")
'Sets pathway for location of HTML text file
Set strHTML = "c:\My Documents\Newsletter.txt"
'Loops throught each contact record
While Not contactRec.EOF
'Performs if contact requires a newsletter
If contactRec("Newsletter") = True Then
Set objMessage = objOutlook.createitem(olMailItem)
With objMessage
.To = contactRec("Email")
.Subject = contactRec("FirstName") & " " & contactRec("Surname") & _
"'s " & "Denca Newsletter"
.HTMLBody = strHTML
.Send
End With
End If
contactRec.MoveNext
Wend
Set contactRec = Nothing
Set objOutlook = Nothing
Set objMessage = Nothing
End Sub
BlueMeanie
May 13 2004, 10:48 AM
Got the code running now, I had put :-
Set strHTML = "c:\My Documents\Newsletter.txt"
......instead of :-
strHTML = "c:\My Documents\Newsletter.txt"
Idiot!
danishani
May 13 2004, 11:12 AM
Glad u got it going

Daniel
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.