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

Send an email through access and Outlook

Status
Not open for further replies.

Kysteratwork

Technical User
Jan 3, 2005
45
LU
Hi All,

I have a serious question:

What code do I have to put for a command button, in order send an email to the address located in the textfield EmailAddress (via Outlook?)

I can't make the EmailAddress Field Clickable, since I wouldn't be able to add a new record without the code wanting to launch the send process, I presume...

Thank you in advance for any indication you may have...
 
wrong forum, try the microsoft access forms forum.



Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Dim appOutlook As New Outlook.Application
Dim omItem As MailItem
Dim ReqId As String

ReqId = Me.txt1.Value
Set omItem = appOutlook.CreateItem(olMailItem)

omItem.To = "email_address"
omItem.DeleteAfterSubmit = True
omItem.Subject = "Your subject"
omItem.Body = "Your email body"
omItem.Send
 
Thanks dbadmin,

However, I get an error message at:
appOutlook As New Outlook.Application

saying
User-defined type not defined

Any idea what this may be referring to?


Kysterathome
 
You have to refer to the Outlook object in the Access application. Open up a VBA window, and under Tools, select References, and select "Microsoft Outlook xx.0 Object Library" (the xx is whatever version you're running).

Then you can use the objects in the OL library in your VBA app.

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
Thanks, now it works, and I understand what the code does. However, I was thinking, would it be possible for the code just to open a new Outlook window with the To: field filled out?


 
Thank you all!

I found the answer. The code is:

Private Sub btnEmail1_Click()
On Error GoTo Err_btnEmail1_Click

DoCmd.SendObject , , , EmailAddress

Exit_btnEmail1_Click:
Exit Sub

Err_btnEmail1_Click:
MsgBox Err.Description
Resume Exit_btnEmail1_Click

End Sub

Kysteratwork
 
Kysteratwork,

Please post your questions in the appropriate forum, even though you were able to get an answer this time. This forum is for Microsoft SQL Server Programming which uses Transact-SQL. There are other forums for Microsoft Access and other applications.

So who cares where I post you might ask? Your post could be 'red-flagged' for being inappropriate for this forum. Then the management could remove it from the site. So, please post in appropriate forums.

Thank you.

-SQLBill

Posting advice: FAQ481-4875
 
I am not ignorant or careless, just new, so thank you for the warning. I will pay more attention in the future.

Kysteratwork
 
Krysteratwork,

I hope you didn't misunderstand me. I realized you were new and at no time did I think you were "ignorant or careless". If I had thought otherwise, I would just have 'red-flagged' your post instead of informing you of the need to post in appropriate forums.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top