Outlook Automation

M

Michael Dawson

I have the following code which creates an email and
attaches a file.

It works fine on my machine, but when I try to run it on
another machine I get the following error message:

Run time error '458'
Variable uses an automation type not supported in Visual
Basic.

On debug it refers to this line of code :

Set olApp = New Outlook.Application


Both machines run Win 98 and Access 2000. The only
difference is mine has Outlook 2002 and the other machine
runs Outlook 2000.

Here is my code:

Dim FileName As String
Dim olApp As Outlook.Application
Dim objNewMail As Outlook.mailitem

Set olApp = New Outlook.Application
Set objNewMail = olApp.CreateItem(olMailItem)
Set fs = CreateObject("scripting.filesystemobject")

FileName = "F:\database\emailfiles\NewClientList_" & Format
(Forms!NewClientList!Text0, "ddmmyy") & ".pdf"

If WriteToIniFile("Acrobat PDFWriter", "pdffilename",
FileName, "C:\windows\system\pdfwritr.ini") Then
DoCmd.OpenReport "pdf_newclientlist"
End If

With objNewMail
..Subject = "New Client List for W/E " & Forms!
NewClientList!Text0
..Body = "Adobe Acrobat Reader is required to view this
file." & Chr(10) & Chr(12) & "If you do not have it you
can download it from
http://www.adobe.com/products/acrobat/readermain.html." &
Chr(10) & Chr(12) & Chr(10) & Chr(12)
..Attachments.Add (FileName)
..Display
End With


Am abit stuck with this, any help would be much
appreciated.

Thanks in advance

Michael Dawson
 
D

Dan Artuso

Hi,
In order for this kind of thing to work with different versions of Outlook,
you must use what's called 'late binding'. In other words, once you are done your
testing on your dev box, remove the reference to the Outlook library, change the
declarations for ALL Outlook objects to As Object and use CreateObject in place of
Set olApp = New Outlook.Application
So it becomes:
Set olApp = CreateObject("Outlook.Application")

You can still use the CreateItem method of the app object of course to create other Outlook items.
The other thing you must do is replace ALL Outlook constants with their numerical value.
To find these values out, while you still have your reference set, from the immediate window
type in:

?olMailItem

and you'll get the value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top