UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Sending a HTML email    
 
   
BlueMeanie
post May 12 2004, 08:26 AM
Post #1

UtterAccess Addict
Posts: 173
From: Liverpool, UK



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
Go to the top of the page
 
+
good_patriot
post May 12 2004, 08:32 AM
Post #2

UtterAccess Veteran
Posts: 332



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.
Go to the top of the page
 
+
BlueMeanie
post May 12 2004, 08:49 AM
Post #3

UtterAccess Addict
Posts: 173
From: Liverpool, UK



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.
Go to the top of the page
 
+
danishani
post May 12 2004, 10:09 AM
Post #4

UtterAccess VIP
Posts: 4,162
From: Washington, USA



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
Go to the top of the page
 
+
BlueMeanie
post May 13 2004, 03:43 AM
Post #5

UtterAccess Addict
Posts: 173
From: Liverpool, UK



Thanks for the info Dani, I will give this a go sometime today.

Cheers

Paul
Go to the top of the page
 
+
BlueMeanie
post May 13 2004, 09:17 AM
Post #6

UtterAccess Addict
Posts: 173
From: Liverpool, UK



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



Go to the top of the page
 
+
BlueMeanie
post May 13 2004, 10:48 AM
Post #7

UtterAccess Addict
Posts: 173
From: Liverpool, UK



Got the code running now, I had put :-

Set strHTML = "c:\My Documents\Newsletter.txt"

......instead of :-

strHTML = "c:\My Documents\Newsletter.txt"

Idiot!


Go to the top of the page
 
+
danishani
post May 13 2004, 11:12 AM
Post #8

UtterAccess VIP
Posts: 4,162
From: Washington, USA



Glad u got it going (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif)

Daniel
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 26th May 2013 - 04:22 AM