Problem with Access / Redemption

I'm trying to overcome the security screen that Access displays when sending an email message via Outlook.
I have dowload the Redemption dll, added it to the registry and made a reference to it and Outlook in the Program Reference Library.
I have also taken some code from an Access book - "Microsoft Access 2010 Programmers Reference - Chapter 18 Page 679)" see code below to try and send an email and bypass the MS security message.
Unfortunatel when I execute the code I get the  following error "Object variable or With block variable not set" when it tries to execut the code line (see code line 11) -
                             Set olMailItem = olApp.CreateItem(olMailItem)
and I'm not sure why.

The only modification I have made to the code snippet is to add the line (see code line 8)
                                Dim objSafeMail                    As Object
as I kept getting a compile error on (see code line 21)
                                Set objSafeMail = New Redemption.SafeMailItem
If anyone can indicate what I'm doing wrong and/or how to overcome this problem it would be greatly appreciated


Public Function SendEmailWithRedemption(sEmailTo As String, _
                                        sEmailSubjectMatter As String, _
                                        sEmailMessage As String)

    ' Define app variable and get Outlook using the "New" keyword
    Dim olApp                          As New Outlook.Application
    Dim olMailItem                     As Outlook.mailItem
    Dim objSafeMail                    As Object
            
    ' Create a new email object
    Set olMailItem = olApp.CreateItem(olMailItem)
    
    ' Add the To/Subject/Body to the message and display the message
    With olMailItem
        .To = sEmailTo
        .Subject = sEmailSubjectMatter
        .Body = sEmailMessage
    End With
    
    ' Create and send the mail with Redemption
    Set objSafeMail = New Redemption.SafeMailItem
    objSafeMail.Item = olMailItem
    objSafeMail.Send
    
    ' Release all object variables
    Set olMailItem = Nothing
    Set olApp = Nothing
       
       
End Function

Open in new window

AdlermAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
olMailItem is an enumerated constant in outlook.  Try revising your code like this to not use olMailItem as a variable name:


Public Function SendEmailWithRedemption(sEmailTo As String, _
                                        sEmailSubjectMatter As String, _
                                        sEmailMessage As String)

    ' Define app variable and get Outlook using the "New" keyword
    Dim olApp                          As New Outlook.Application
    Dim objMailItem                   As Outlook.mailItem
    Dim objSafeMail                    As Object
            
    ' Create a new email object
    Set objMailItem= olApp.CreateItem(olMailItem)
    
    ' Add the To/Subject/Body to the message and display the message
    With objMailItem
        .To = sEmailTo
        .Subject = sEmailSubjectMatter
        .Body = sEmailMessage
    End With
    
    ' Create and send the mail with Redemption
    Set objSafeMail = New Redemption.SafeMailItem
    Set objSafeMail.Item = objMailItem
    objSafeMail.Send
    
    ' Release all object variables
    Set objMailItem = Nothing
    Set olApp = Nothing
       
       
End Function 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AdlermAuthor Commented:
Hi mbizup

My apologies for taking sometime to reply. I hadn't hear from anyone for several days after posting my question (people may have been on holidays over the New Year break). I then received notification that my question was to be re-routed to a different zone etc and then you responded and to be quite frank I had to recall what I was initially trying to do. Anyway I did what you suggested to the code and things worked fine - Except - that the e-mail goes to Outlook but isn't forwarded on to the recipient. When I open Outlook I can see the e-mail , the recipient To e-mail address is correct, Subject matter is correct etc but Outlook is not forwarding it on to the intended recipient. Do I need to do something else so the e-mail doesn't get stuck in Outlook.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.