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

Outlook Error in Access Runtime Revisited

Status
Not open for further replies.

jhaganjr

IS-IT--Management
Dec 11, 2002
62
US
Hello,

Last week I posted a problem and was advised to do better error trapping. I've done that, so here is the problem again...

I've been using code for an Outlook object - which I found through this forum - for years with no problems. However all my users had full versions of Access on their machines.

Now they have only runtime versions of Access. And the function creates a runtime error.

Note: I and 2 other users have full versions of Access and the code runs without a hitch. It's only the Access runtime users that get a runtime error.

All users run Outlook 2003 - those with full versions of Access as well as those with Access runtime only.

For the users running Access runtime only, the error occurs on "Set objOutlook = CreateObject("Outlook.Application")" in the code below.

The error code & description is:
-2147024770 Automation Error
The specified module could not be found

For reference, I am packaging MSOUTL.OLB with the database when I distribute it to my runtime users.

Does anyone have any insight into this problem? The Outlook code follows:

<start code>
Public Sub fctnOutlook(Optional FromAddr, Optional Addr, Optional CC, Optional BCC, _
Optional Subject, Optional MessageText, Optional Vote As String = vbNullString, _
Optional Urgency As Byte = 1, Optional EditMessage As Boolean = True, Optional AttachmentPath)

'I got this code from 'via some links through tek tips.com - added the attachment path piece myself

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg

If Not IsMissing(FromAddr) Then
.SentOnBehalfOfName = FromAddr
End If

If Not IsMissing(Addr) Then
Set objOutlookRecip = .Recipients.Add(Addr)
objOutlookRecip.Type = olTo
End If

If Not IsMissing(CC) Then
Set objOutlookRecip = .Recipients.Add(CC)
objOutlookRecip.Type = olCC
End If

If Not IsMissing(BCC) Then
Set objOutlookRecip = .Recipients.Add(BCC)
objOutlookRecip.Type = olBCC
End If

If Not IsMissing(Subject) Then
.Subject = Subject
End If

If Not IsMissing(MessageText) Then
.Body = MessageText
End If

If IsNull(Vote) = False Then
.VotingOptions = Vote
End If

Select Case Urgency
Case 2
.Importance = olImportanceHigh
Case 0
.Importance = olImportanceLow
Case Else
.Importance = olImportanceNormal
End Select

If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

If EditMessage Then
.Display
Else
.Save
.Send
End If

End With
Set objOutlook = Nothing

End Sub
<end code>

Thank you!
Joe
 
I don't know anything about this challenge, and I don't know whether late binding will solve this, but if nothing else, you could perhaps try?

One of my guesses here, is that there's something wrong with the references causing this, and my favoured approach for reference hassles when automating, is using late binding.

How - remove the references to outlook, and not package anything with it, declare all of the outlook objects as only objects

[tt] Dim objOutlook As object ' Outlook.Application
Dim objOutlookMsg As object ' Outlook.MailItem[/tt]

You will also have to change the following line

[tt] Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
' to
Set objOutlookMsg = objOutlook.CreateItem(0) ' 0 = olMailItem[/tt]

The same way you need to alter all of the current Outlook constants (starting with ol...), to find the values they represent, in the immediate pane (ctrl+g), type

[tt]?olTo [/tt]

hit enter, and the result should be 1

When you've packaged etc, try it on a computer where no Access nor runtime has been installed before.

Since this code instantiates a new instance of Outlook, regardless of whether it is open or not, then does not close it, (.quit), that might give some challenges the second time the code is run?

Roy-Vidar
 
The fix is to change the object command

From: Set objOutlook = CreateObject("Outlook.Application")

To: Set objOutlook = CreateObject("Outlook.Application", "localhost")

Thanks to Andy who responded to the first thread!

Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top