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

Save Record Then Send To Outlook

Status
Not open for further replies.

pjd218

Technical User
Apr 14, 2008
40
US
I have a form that I compose an email to a contact then a command button sends the info to Outlook. Also on that form is a command button to save the record to the contact notes table.

The problem I have found is that if I send to outlook prior to saving, then try to save the record, it does not update my contact notes table.

What I need to do is combine the two routines into one so that the record is saved, then sent to outlook.

Code for each command follows:
__________________________________
Private Sub Command7_Click()
Dim email, ref, destination, notes As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

'**gathers information from your form. this sets the string variable to your fields
email = Me!email_address
ref = Me!subject
notes = Me!message

'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'***creates and sends email
With objEmail
.Display
.To = email
.subject = ref
.HTMLBody = "<p>" & notes & "<p>" & .HTMLBody

End With

Exit Sub
End Sub
____________________________________
Private Sub Command8_Click()

On Error GoTo Command8_Click_Err

DoCmd.SetWarnings False
DoCmd.OpenQuery "ContactLogEntryFMAppendNewEmailQRY", acViewNormal, acEdit
DoCmd.SetWarnings True
DoCmd.Close


Command8_Click_Exit:
Exit Sub

Command8_Click_Err:
MsgBox Error$
Resume Command8_Click_Exit

End Sub
__________________________________

Both routines work fine, but I sometimes forget to save the record first.

As always, help is appeciated.
 
Code:
Private Sub Command8_Click()

    Dim email, ref, destination, notes As String
    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem

    On Error GoTo Command8_Click_Err
    
    '**saves record
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "ContactLogEntryFMAppendNewEmailQRY", acViewNormal, acEdit
    DoCmd.SetWarnings True
    DoEvents
    
    '**gathers information from your form.  this sets the string variable to your fields
    email = Me!email_address
    ref = Me!subject
    notes = Me!message
    
    '***creates an instance of Outlook
    Set objOutlook = CreateObject("Outlook.application")
    Set objEmail = objOutlook.CreateItem(olMailItem)
    
    '***creates and sends email
    With objEmail
        .Display
        .To = email
        .subject = ref
        .HTMLBody = "<p>" & notes & "<p>" & .HTMLBody
    End With

Command8_Click_Exit:
    Exit Sub

Command8_Click_Err:
    MsgBox Error$

    Resume Command8_Click_Exit
    DoCmd.Close
End Sub

untested

HTH << MaZeWorX >> Remember amateurs built the ark - professionals built the Titanic [flush]
 
MW,

Thanks.

I knew it was not that complicated.

Works perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top