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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access sendobject - delete sent mail from outlook?

Status
Not open for further replies.

mudstuffin

Technical User
Sep 7, 2001
92
0
0
GB
Hi.

I have a form in a db where users log-in, and if they get their password wrong, the form sends an email to me using docmd.sendobject (if they havent got outlook open, it opens it up invisibly).

This then leaves an email in the users sent folder in outlook. Is there a way that I can have that email deleted after the sendobject has sent the email, as I would rather the users did not have the email sitting in theie sent folder?

Many Thanks,


mudstuffin
 
How are ya mudstuffin . . . . .

I knew I had done something in earlier years with OtuLook in this regard, but it was very hard to find (I finally realized just how big my library has become) . . .

Anyway , , , found it! So, in a [blue]module[/blue] in the [blue]modules window[/blue], copy/paste the following [purple]function:[/purple]
Code:
[blue]Public Function DelSentOK(SubjectLine As String) As Boolean
   Dim Fldr As MAPIFolder, SentItem As Object
   Dim Msg As String, Style As Integer, Title As String, DL As String
   
   On Error GoTo NoMail

   DL = vbNewLine & vbNewLine
   Set Fldr = CreateObject("Outlook.Application") _
                           .GetNameSpace("MAPI") _
                           .GetDefaultFolder(olFolderSentMail)
   Set SentItem = Fldr.Items(SubjectLine) 'Break On Error Here![green][/green]
   SentItem.Delete
   DelSentOK = True

ExitErr:
   Set SentItem = Nothing
   Set Fldr = Nothing
   Exit Function

NoMail:
   If Err.Number = -2147221233 Then
      Msg = "Sent Mail with subject line:" & DL & _
            "'" & SubjectLine & "'" & DL & _
            "Not Found!"
      Style = vbInformation + vbOKOnly
      Title = "Mail Not Found Error! . . ."
      MsgBox Msg, Style, Title
   Else
      Msg = "Error Number " & Err.Number & DL & _
             Err.Description
      Style = vbCritical + vbOKOnly
      Title = "System Error!"
      MsgBox Msg, Style, Title
   End If
   
   Resume ExitErr
End Function[/blue]
The function returns [blue]True[/blue] if deletion was successful, [blue]False[/blue] otherwise (with a message).

To call the routine (example):
Code:
[blue]Variable = DelSentOK([purple][b]SubjectLine[/b][/purple])[/blue]
Things to take into account when making the call:
[ol][li]([purple][purple]SubjectLine[/purple][/purple] is the key for finding the sent e-mail. When you send the e-mail, this should be something unique and saved in a variable for the search.[/li]
[li]The function does not take into account multiple e-mails with the same [purple]SubjectLine[/purple]. You may want to loop until an error is displayed![/li]
[li]Be aware: thre is a finite amount of time between the time the e-mail is sent and when it appeats in the [blue]Sent Folder.[/blue] Its up to you to work this out![/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top