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!

Access to Outlook??? 1

Status
Not open for further replies.

BT24

Programmer
Joined
Aug 19, 2002
Messages
76
Location
CA
Hello

What i would Like to know is i have a memo on my main form that i would like that when it is filled in that it will be automatically e-mailed(outlook) to a known e-mail address. if this is possible that would be great, or even a version of this would be great, what i have now is this:

Private Sub Maintenance_Click()
If MsgBox("Email Todd Harvey About the Problem With the Truck", vbOKCancel) = vbOK Then
DoCmd.RunMacro ("macOutlook")
Else
DoCmd.OpenForm ("frmTruckSheet"), acNormal
End If
End Sub

the macro is a RunApp to Outlook. if this is the best that i can do then thats great. Thanks for the help

Iamuseless
 
Useless - all you need to do is replace your statement of
Code:
DoCmd.RunMacro ("macOutlook")
with
Code:
docmd.SendObject type, name, format,to, cc, bcc, subject, message, edit, template


All of the parameters are optional. So, you have a form with a memo field which is the data you want to send, I'll call it memData. If you want, you could also have a text field with the email address you want to send. I will call it txtEmail.
You could also have a text box with a subject line, called txtSubject.

So your statement would now be :
Code:
docmd.SendObject , , ,txtEmail, , , txtSubject, memData
Note If you are not very familiar with VB, the commas are basically place holders telling Access to ignore the parameter that is supposed to be there. In other words, the first parameter of type we are not using so we put a comma to tell VB to go to the next parameter. When you type this in, you will get the popup help to tell you which field you are on.

Also, if you do not want to have a field on the form for Email address and Subject (i.e. it will always be the same), You can hardcode the email and subject like this :

Code:
docmd.SendObject , , ,"JohnSmith@AAA.com", , , "This is the subject", memData

One last note, the Edit parameter tells VB that you want to edit the email before you send. If set to TRUE, the email will open and you can make changes and then send it. If set to FALSE or omitted, the email will be created and sent immediately without interaction.

One (more) last note. If you are using Office XP, you may be warned that a third party app is trying to send an email on your behalf. You will have to click YES or OK (can't remember) to allow it. This depends on the security template being used by Outlook.

Let me know if you have any questions

Jay
 
Thanks Alot Jay, the code works but when i close the dialog box it gives me error 2501 and other then that i think that it works fine thanks alot
 
Jay also the "memData" title is the only information that is being put on the Outlook form, its not the info that is actually in the Box
Thanks again
 
Useless - you just need to put in some error handling code.

Code:
On Error GoTo Send_err

docmd.SendObject , , ,"JohnSmith@AAA.com", , , "This is the subject", memData  

Exit Sub
    
Send_err:
    
        If Err.Number = 2501 Then
            Err.Clear  
        End If


This will catch the 2501 error and clear it which will gracefully go back to the form where you started the SendObject method.

You could also give feedback to your user saying "Email cancelled" using a messagebox if you wanted.

Let me know if you have any other questions.

Jay
 
Thanks Jay!!!!!you have really been a big help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top