• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Sending Message from Access

I have this line in my code:

Dim objApp As outlook.Application

I have the Office Object 9.0 selected in the tools/references.

I get error that this is not a defined object

Any Ideas?

Thanks
0
jwhiteman1967
Asked:
jwhiteman1967
  • 3
  • 2
  • 2
  • +1
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Outlook.Application is part of the 'Microsoft Outlook 9 Object Model', not the Office object model.  
Go back to Tools:References and check Outlook.
0
 
rockiroadsCommented:
is it failing on that line of code?

What u need is Microsoft Outlook, not Office object checked



Have u tried the alternative, by creating an object

dim objAp as Object

set objApp = CreateObject("Outlook.Application")

0
 
EMCITCommented:
Set NewMessage = ol.CreateItem(olMailItem)
      NewMessage.To = "emailaddress@whatever.com"
      NewMessage.Subject = "BlahBlahBlah"
      NewMessage.Attachments.Add "C:\Filename.xxx", olByValue
      NewMessage.Send
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rockiroadsCommented:
What do u want to send? if its just text, u do not need the outlook object,

Doing

    DoCmd.SendObject , , acFormatXLS, "fred@smith.com", , , "Subject", "Message", False

will send a email

If u want an example of outlook automation
see my code example here   http://www.experts-exchange.com/Databases/MS_Access/Q_21866975.html

This link also provides an example in sending emails via CDO. Advantage of this is u dont get that security message
Disadvantage is u have to know the smtp server

0
 
rockiroadsCommented:
Ah, I see EMCIT has already provided an example
Sorry EMCIT, I guess I should of refreshed. That last post is my standard post when responding to questions like this.
0
 
jwhiteman1967Author Commented:
All you suggestions were right on target. The info I had said Office and not Outlook.  Jeeez.

Now I am getting this error:

ActiveX Cannot Create Object (429)

Any ideas?
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim

>ActiveX Cannot Create Object (429)
Show us your code.  This usually happens because you are trying to Set something without Dim-ming it first.
0
 
jwhiteman1967Author Commented:
FOUND THIS ON THE NET. SO I DID NOT WRITE IT. ANY HELP IS APPRECIATED!

Public Sub SendOutlookMessage( _
    strEmailAddress As String, _
    strEmailCCAddress As String, _
    strEmailBccAddress As String, _
    strSubject As String, _
    strMessage As String, _
    blnDisplayMessage As Boolean, _
    Optional strAttachmentFullPath As String)
   
'* Copy this code and paste it into a new Access
'* Module. Click Tools > References and make sure
'* that "Microsoft Office Outlook x.0 Object Library"
'* is checked.
'*
'* This subroutine sends an e-mail message through
'* MS Outlook. If the "blnDisplayMessage" parm is
'* set to "False", the message is placed in the
'* Outlook Outbox. "True" displays the message, and
'* user will have to click "Send" to send it.
'*
'* Ex.:
'*
'* SendOutlookMessage _
'*      "john@doe.com", _
'*      "ccJane@doe.com", _
'*      "bccSue@doe.com", _
'*      "Subject", _
'*      "Body of Message", _
'*      False, _
'*      "C:\My Documents\MyAttachmentFile.txt"
   
Dim objApp As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim blnOutlookInitiallyOpen As Boolean
Dim strProcName As String

On Error Resume Next
strProcName = "SendOutlookMessage"

blnOutlookInitiallyOpen = True
Set objApp = GetObject(, "Outlook.Application")
If objApp Is Nothing Then
    Set objApp = CreateObject("Outlook.Application")
    '* Outlook wasn't open when this function started.
    blnOutlookInitiallyOpen = False
End If
If Err <> 0 Then Beep: _
    MsgBox "Error in " & strProcName & " (1): " _
        & Err.Number & " - " & Err.Description: _
    Err.Clear: _
    GoTo Exit_Section

'Create the message
Set objOutlookMsg = objApp.CreateItem(olMailItem)
If Err <> 0 Then Beep: _
    MsgBox "Error in " & strProcName & " (2): " _
        & Err.Number & " - " & Err.Description: _
    Err.Clear: _
    GoTo Exit_Section
   
With objOutlookMsg
    Set objOutlookRecipient = .Recipients.Add(strEmailAddress)
    objOutlookRecipient.Type = olTo
    If strEmailCCAddress = "" Then
    Else
        Set objOutlookRecipient = .Recipients.Add(strEmailCCAddress)
        objOutlookRecipient.Type = olCC
    End If
    If strEmailBccAddress = "" Then
    Else
        Set objOutlookRecipient = .Recipients.Add(strEmailBccAddress)
        objOutlookRecipient.Type = olBCC
    End If
    .Subject = strSubject
    .Body = strMessage

    '* Add attachments
    If Not IsMissing(strAttachmentFullPath) Then
        If Trim(strAttachmentFullPath) = "" Then
        Else
            Set objOutlookAttach = .Attachments.Add(strAttachmentFullPath)
            If Err <> 0 Then Beep: _
                MsgBox "Error in " & strProcName & " (3): " _
                    & Err.Number & " - " & Err.Description: _
                Err.Clear: _
                GoTo Exit_Section
        End If
    End If

    If blnDisplayMessage Then
        .Display
    Else
        '* Send message by putting it in the Outbox
        .Send
    End If
End With
   
If Err <> 0 Then Beep: _
    MsgBox "Error in " & strProcName & " (99): " _
        & Err.Number & " - " & Err.Description: _
    Err.Clear: _
    GoTo Exit_Section
   
Exit_Section:
    On Error Resume Next
    If Not blnOutlookInitiallyOpen Then
       objApp.Quit
    End If
    Set objApp = Nothing
    Set objOutlookMsg = Nothing
    Set objOutlookAttach = Nothing
    Set objOutlookRecipient = Nothing
    On Error GoTo 0
End Sub


Invoked with:
'SendOutlookMessage "email@somewhere.com", "email@somewhere.com", "", "Testing Routine", "Testing", False, filename

Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now