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 Function Causes Runtime Error in Access Runtime versions 1

Status
Not open for further replies.

jhaganjr

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

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.

Does anyone have any insight into this phenomena? 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
 
Any chance you could post the whole error message(s) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Not only post the error message but if you could put a break in your code and show us which line the code is generating an error on would be nice as well.

Thanks


Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
1) The error is ...

Automation Error
The specified module could not be found

2) How do you put a code break into a runtime version? Remember, in the full versions of Access - where I can put a break in the code - the code runs fine. After the db is packaged and distributed to machines running only Access runtime, the code fails.

Thanks.
Joe
 
The thing with Runtime is that error trapping is left up to you. This is probably something that Access either works through or doesn't have a problem with, but because YOU are not trapping this error specifically in runtime, it is causing this failure.

Runtime comes with an Error Trapping wizard, have you run that?

Also, now that you are using something much closer to a realy development environment, you need to step up you Error Trapping game. There is a reason a lot of programmers use line numbers and so forth, it makes it easier to troubleshoot.

Here is a good ErrorHandler from ChrisO at Utteraccess.com...

Under ErrHandler place something like:

Code:
ErrorHandler:
    DisplayError "SetScreenForStartOfSearch", Me.Name
    Resume ExitProcedure

Then the module contains:

Code:
Option Explicit
Option Compare Text

Private Const conModuleName As String = "mdlHandleErrors"
'
'*******************************************************************************


'   Global error handler for all Procedures.
Public Sub DisplayError(ByVal strProcedureName As String, _
                        ByVal strModuleName As String, _
               Optional ByVal strAdditionalInfo As String = "")

    Dim strMessage As String
    
    '   First get a copy of the current error number and description.
    strMessage = "Error in Module: " & strModuleName & vbNewLine & _
                 "Procedure: " & strProcedureName & vbNewLine & vbNewLine & _
                 "Error Number: " & Err.Number & vbNewLine & _
                 "Error Description: " & Err.Description

    '   Now that the error info has been saved we can use error handling.
    If (conHandleErrors) Then On Error GoTo ErrorHandler

    '   Add any additional info that may have been passed.
    If strAdditionalInfo <> "" Then
        strMessage = strMessage & vbNewLine & vbNewLine & _
                     "Additional Information:" & vbNewLine & _
                     strAdditionalInfo
    End If
            
    '   Display the original error.
    MsgBox strMessage, vbCritical, "Runtime error detected"
    
ExitProcedure:
    Exit Sub

ErrorHandler:
    '   Do not recall this error procedure...simply display the new error.
    MsgBox "Error in Module: mdlHandleErrors" & vbNewLine & _
           "Procedure: DisplayError" & vbNewLine & vbNewLine & _
           "Error Number: " & Err.Number & vbNewLine & _
           "Error Description: " & Err.Description
                 
    Resume ExitProcedure
    
End Sub


----------------------------------------------------
And another method would be like so:

Code:
ErrorHandler:
    GeneralErrorHandler Err.Number, Err.Description, "SetScreenForStartOfSearch", Me.Name
    Resume ExitProcedure

With the module having:

Code:
Public Sub GeneralErrorHandler(lngErrNumber As Long, strErrDesc As String, strModuleSource As String, strProcedureSource As String)

Dim strMessage As String

'build the error message string from the parameters passed in
strMessage = "An error has occurred in the application."
strMessage = strMessage & vbCrLf & "Error Number: " & lngErrNumber
strMessage = strMessage & vbCrLf & "Error Description: " & strErrDesc
strMessage = strMessage & vbCrLf & "Module Source: " & strModuleSource
strMessage = strMessage & vbCrLf & "Procedure Source: " & strProcedureSource

'display the message to the user
MsgBox strMessage, vbCritical

End Sub

Either way, or even another way, you will need to beef up the error trapping.

Sean.
 
That makes sense. I'll give it a go and then come back with better information.

Thanks!
Joe
 
Joe,

I have the same problem. I am migrating from a notebook which had Office XP Pro and then Office 2003 SBE. I have a spreadsheet that uses Outlook to send emails using similar code to the code you posted.

On the new notebook I have installed Office 2003 SBE and Access 2002. I get the following error when attempting to send an email.

Run-time error '-2147024770(8007007e)'

Automation error
The specified module could not be found.

The "Set olApp = New Outlook.Application" is the line of code that generates the error.

Dim olApp As Outlook.Application
Set olApp = New Outlook.Application

I have the same references on both machines.

Visual Basic For Applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Outlook 11.0 Object Library
Microsoft Office 11.0 Object Library


Andy
 
Joe,

I have found a workaround on the web which fixes the problem for me.


This does not work
Set olApp = CreateObject("Outlook.Application")

This does work.
Set olApp = CreateObject("Outlook.Application", "localhost")

Andy
 
Andy, you are awesome!

That did it.

Thanks a million!
Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top