Check An Email Has Been Sent

ddrew

seasoned user
Local time
Today, 17:56
Joined
Jan 26, 2003
Messages
911
I have some code that sends an email when the database is registered. The problem is that depending on a users security settings on their PC they can stop the email from being sent (2007) How can I add to the code to make it check that the user hadnt cancelled the email?

My code is:

Code:
Private Sub btnRegister_Click()
    Dim olApp As Object
    Dim objMail As Object

    On Error Resume Next    'Keep going if there is an error
    Set olApp = GetObject(, "Outlook.Application")    'See if Outlook is open

    If Err Then    'Outlook is not open
        Set olApp = CreateObject("Outlook.Application")    'Create a new instance
    End If
    DoCmd.Hourglass True

    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
        'Set body format to HTML
        .BodyFormat = olFormatHTML
        .To = "da.drew@hotmail.co.uk"
        .Subject = "Gundog Manager Registration"

        .HTMLBody = "<HTMLtags>This email confirms that a new user " & _
                    olApp.Application.Session.Accounts.Item(1).SmtpAddress & _
                    " has registered a copy of Gundog Manager.  The registration number of this copy is " & Me.RegistrationNumber & "</HTMLtags>"
        .Send
    End With
    DoCmd.Hourglass False
    MsgBox "Operation completed successfully"
    Me.chkboxRegistar = True
    Me.Requery

End Sub
 
Remove the On Error Resume Next line and replace it with a proper Error handling procedure. If memory serves right, if an operation is cancelled Error 2501 is thrown. Check the Error number and take action appropriately..
 
Remove the On Error Resume Next line and replace it with a proper Error handling procedure. If memory serves right, if an operation is cancelled Error 2501 is thrown. Check the Error number and take action appropriately..

Because the email is sent automatically, I found the onlty way it an be stopped is if the user has no security softwar installed. I read up last night and found that the Outlook window that pops up (Microsft Outlook Security) telling you that another program is trying to access your Outlook program, only appears if there isn't any security software.

I guess the other issue is what about is a user dosen't use Outlook!
 

Users who are viewing this thread

Back
Top Bottom