Link to home
Start Free TrialLog in
Avatar of dminx13
dminx13Flag for United States of America

asked on

Object doesn't support this property or method

Hello~
Trying to recode from Groupwise to Outlook and running into an error. Right now getting Object Doesn't support this property or method on line 53. I got this code off MSDN so I am not sure why it is not happy? I have Outlook references set up as well.  Outlook is open at this point. I'm not even getting to the next section to see if I need to re-write that. I also tried adding this line: Set olApp = CreateObject("Outlook.Application") before line 53 and that did nothing either. Help?
Public Function SendEmail(AddressTo As Variant, Header As String, Message As String, PriorityHigh As Boolean, _
                            Optional AddressCC As Variant, Optional AddressBCC As Variant, _
                            Optional FileAttach As Variant, Optional MessageFromText As Variant)
    '  Function is used to send e-mails through the Groupwise Client
    '  Groupwise must be installed for the function to work
    '  variables
    '  FileAttach tilda delimited string of file names - maximum attachments handled by code is six
    'On Error GoTo Err_Handler
    ' Address Array
    '    Address:  (0, i)=address; mastrRecTo(1, i)=display name
    Dim strTemp As String
    Dim bAttachment As Boolean
    Dim varAttach(5) As Variant
    Dim ccAddress(50, 0) As Variant
    Dim lngCount As Long
    Dim varProxies As Variant
    Dim olApp As New Outlook.Application
    Dim olMailItem As Outlook.MailItem  ' An Outlook Mail item
    Dim i As Integer
    Dim k As Integer
    
    '  If not attachments send through centralized processing
    If IsMissing(FileAttach) = True Then
        Call SendSQLEmail(AddressTo, Header, Message, AddressCC, AddressBCC, FileAttach, MessageFromText)
        
        Exit Function
    End If
    
    
    
    
    If DatabaseAtHome = False Then
        If IsMissing(FileAttach) = True Then
            bAttachment = False
        Else
            bAttachment = True
            '  parse out the names
            k = 0
            Do
                i = InStr(FileAttach, "~")
                If i = 0 Then
                    varAttach(k) = FileAttach
                Else
                    varAttach(k) = Left(FileAttach, i - 1)
                    FileAttach = Mid(FileAttach, i + 1)
                End If
                k = k + 1
                If k > 5 Then Exit Do
            Loop Until i = 0
        End If
    
        ''''Set olApp = New Outlook.Application
        Set olMailItem = olApp.CreateItem(olMailItem)

        With olMailItem
        ''''With oApp
            ''''.Login
            ''''.BodyText = Message
            ''''.Subject = Header
            ''''.RecTo = AddressTo                                  '  Primary Recipient
            .TO = AddressTo
            .Subject = Header
            .Body = Message

            
            If IsMissing(AddressCC) = False Then                '  carbon copy if present
                .RecCc = AddressCC
            End If
            
            If IsMissing(AddressBCC) = False Then               '  blind cardon copy if present
                .RecBc = AddressBCC
            End If
            If IsMissing(varAttach) = False Then                ' Attachments if present
                .FileAttachments = varAttach
            End If
            If IsMissing(MessageFromText) = False Then          '  From Text if Present - user name to appended
                .FromText = MessageFromText                     '  PeopleCenter (User Name)
            End If
            If PriorityHigh = True Then                         '  Message priority id either high or standard
                .Priority = "High"
            Else
                .Priority = "Standard"
            End If
            strTemp = .CreateMessage
            .ResolveRecipients strTemp
            If IsArray(.NonResolved) Then MsgBox "Some unresolved recipients."
            .SendMessage strTemp
            .DeleteMessage strTemp, True
        End With
    
Exit_Here:
        Set olApp = Nothing
        Set olMailItem = Nothing
        
    Else
        MsgBox "Header: " + Header + vbCrLf + "Message: " + Message, vbInformation, "E-Mail Message"
    End If
    
    Exit Function
Err_handler:
    MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
    Resume Exit_Here

End Function

Open in new window

Avatar of dminx13
dminx13
Flag of United States of America image

ASKER

The end result is creating a new mail message with attachments and sending it to a list of people.
ASKER CERTIFIED SOLUTION
Avatar of Jim P.
Jim P.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheNautican
TheNautican

Try to uncomment out line 52
Avatar of dminx13

ASKER

Jim P - We run Outlook off of a packaged environment. It isn't installed locally. It will always be Outlook not express.

We are moving to Windows 7 and from what I have heard I will have very little access to anything locally so would this work in a locked down environment?

TheNautican. I have. Same error :-(
Jim P - We run Outlook off of a packaged environment. It isn't installed locally. It will always be Outlook not express.

I actually haven't had to try it in a locked down environment, so I'm not able to answer that directly.

The way I always did it was to set a reference (VBA window (<Alt>+<F11> --> Tools --> References) in the the DB and then selected the Send Mail object from the list. The file was copied to the C:\Windows\System32 folder already. But in a more restrictive environment  you can copy the vbSendMail.dll to any "universal" location and then go into the references and add it from that location. It will work the same way as long as the location is the same as it is in the references.

It is not pretty but it works.
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial