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

Tracking Email

Status
Not open for further replies.

naturalsn

Technical User
Apr 26, 2007
68
GB
Hi

I was hoping someone could perhaps assist.

I am currently using a form in Access to Send and Email to outlook. This work perfect. But I am hoping due to the fact that only emails sent from the DB are being sent to Clients in the DB keep a copy of what was sent. Just in a Table. Due to various people working in the DB we can then see if the Client has been contacted. I am currently using the following code, and added additional to try and insert what was sent in the email into a Tbl called TblEmailsSent.

Upon changing the code. I noted that when my MS Security Popup comes up where I have to select how long i will grant access to outlook, that now appears twice, meaning i have three boxes to click prior to the email being sent.

The code i am using is as follow Everything that is in blue, is what i just added to place the data in my TblemailsSent Talbe

2 Questions -

1. Currently upon clicking send. My Security warnings popup x3 Why?
2. the email sends perfectly but no data appears in my table.

Can someone please advise one where i might be going wrong.

Kind Regards
Sn

Code:
Private Sub SendEmail_Click()

    [blue]Dim db As DAO.Database
    Dim MailList As DAO.Recordset[/blue]
    Dim appOutLook As Object
    Dim oInsp As Outlook.Inspector
    Dim MailOutLook As Outlook.MailItem
    Set appOutLook = Outlook.Application
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    Set oInsp = MailOutLook.GetInspector
    Set WordDoc = oInsp.WordEditor
        
    [blue]Dim MySentEmail As Recordset
    Set MySentEmail = CurrentDb.OpenRecordset("TblEmailsSent")[/blue]
    
    With MailOutLook
    
    .BodyFormat = olFormatRichText
    .To = Me.Email_Address
    .CC = IIf(IsNull(Me.CC_Address), "", Me.CC_Address)
    .BCC = IIf(IsNull(Me.BCC_Address), "", Me.BCC_Address)
    .Subject = Me.Mess_Subject
    .Body = vbCrLf & vbCrLf & "Reference No: " & Me.ID & vbCrLf & vbCrLf & Me.mess_text & vbCrLf & vbCrLf & .Body
    If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
    .Attachments.Add (Me.Mail_Attachment_Path)
    End If
    .Send
    
    [blue]MySentEmail.AddNew
    MySentEmail("ID") = Me.ID
    MySentEmail("emailaddress") = MailOutLook.To
    MySentEmail("emailsubject") = MailOutLook.Subject
    MySentEmail("emailbody") = MailOutLook.Body
    MySentEmail("DateSent") = Now()
    MySentEmail.Update

    MailList.MoveNext[/blue]
    
 Set MailOutLook = Nothing
   Set appOutLook = Nothing

            
    End With
    'MsgBox MailOutLook.Body
    Exit Sub
email_error:
    MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
    Resume Error_out
Error_out:
End Sub
 
I think you would learn more by placing a breakpoint at the top of your code, then step through the code one line at a time. By doing that you will see where in your code that Outlook is popping up the interface.

As a hint, it is where you are referencing message objects.

Learn from the mistakes of others. You won't live long enough to make all of them yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top