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

Sending Emails 2

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
One of my customers has asked for a facility to send email from access (Which I can see from elsewhere on the net shouldnt be too hard to program. (And all their emails are to opted in people, no spam)

What they want to do is to use access to create the emails from a template (a kind of manual mail merge I guess), and then store them in the drafts folder in Outlook.

So, before I start to program this, has anyone got any gotchas I should avoid, or commments?

Cheers

K
 
dont see any problem go ahead start and if you hit a problem post the problem and we will try to help you

I will try my best to help others so will others do!!!!!
IGPCS
Brooklyn, NY
 
small point, i guess...

When I open an instance of Outlook, or word or excel
for that matter, I use GetObject() first.
If fails, from the error handler I use CreateObject().

This avoids instantiating too many (unecessary), instances.
PS disregard all the inapplicable stuff..

Sub SendEmailTest()
10 On Error GoTo xxx

Dim appOutLook As Outlook.Application, itm As Object, blnCreate As Boolean

20 Set appOutLook = GetObject(, Outlook.Application)
30 Set itm = appOutLook.CreateItem(olMailItem)


40 With itm
50 .To = fEmailAddress("Dan")
60 .Subject = "test" & Date
70 .Body = ""
'.Display
80 .Send
90 End With

100 'If blnCreate Then appOutLook.Quit
xx:
110 Set appOutLook = Nothing
120 Set itm = Nothing
130 Exit Sub
xxx:
140 If err = 2501 Or err.Number = 287 Then
150 Resume Next
160 ElseIf (err = 429 Or err = 462) And (Not blnCreate) Then ' activeX Component can not create object/Remote Server Machine does not exist or is unavailable
170 Set appOutLook = CreateObject("Outlook.Application")
180 blnCreate = True
190 Resume Next
200 Else
210 MsgBox err & vbCrLf & Error$ & vbCrLf & Erl
220 Resume xx
230 End If
End Sub

 
Hmm, I tried your code, and the first line I get the error.
User Defined Type Not Defined for Outlook.Application

Any ideas?
 
User Defined Type Not Defined for Outlook.Application
Either use late binding (Dim appOutLook As Object) or add the Microsoft Outlook Object Library to the references.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ok, silly question, but where can I get the MS Outlook object library on, its not on my list of references on the Dev PC. Is it something I need the office CD for? (I'll google for this as well, so if its obvious then dont need to answer!)

Cheers

K
 
ok, I found it. I still had access in vb debug mode :$ Sorry

K
 
ok, last post tonight.

Is there a good definitive reference on vba on the Net anywhere? - I can find lots of sites, but none seem to be able to answer my questions, and I dont want to just keep coming back to you guys.

(Though if your inclined), I need to access a template email, change the date and the user its adressed to, and then save it to drafts.

Ive figured out if I save instead of send an email, it goes into drafts. However im damned if I can see how to get a template email into access, so I can search through it and swap the place holders for the real data. Ive looked at GetFolderFromID, GetTemplate, and just sitting in debug and exploring the outlook model, but I cant see how to get it.

any help or other sites worth a look would be most appreciated

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top