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

Open Outlook from a text box

Status
Not open for further replies.

Chuck712

Technical User
Mar 1, 2002
133
US
This might have been covered in this forum before, but I need some help with a Contact database. I have a text box that has the email address of the contact and I would like user's to be able to click on the address and have Outlook open, with the contact's name in the To: portion.
All users are using Outlook from their desktops, but they are all running through the network and the database will only be available on the network.
I am not the best at writing code, but can get by.
Any help would be appreciated.
 
In the On_Click event of the text box (which I have named txtEmailAddress) , enter the following code:

Call CreateOLMainItem (Me.txtEmailAddress, "", "")

(Please note that my this code allows you to pass more than just an email address... you can also pass, a subject line, message text, and optionally an attachment... I was going to take them out for this example, but then I thought that you might like to see them.)

In a regular module, enter the following Sub:

Public Sub CreateOLMailItem(strRecipient As String, strSubject As String, _
strBody As String, Optional strAttachment As String)

Dim olkApp As Outlook.Application
Dim olkNameSpace As Outlook.NameSpace

Dim objMailItem As Outlook.MailItem

Set olkApp = New Outlook.Application
Set olkNameSpace = olkApp.GetNamespace("MAPI")
Set objMailItem = olkApp.CreateItem(olMailItem)

With objMailItem
.To = strRecipient
.Recipients.ResolveAll
.Subject = strSubject
If strAttachment <> &quot;&quot; Then .Attachments.Add strAttachment
.Body = strBody
.Display
.Send
End With

Set objMailItem = Nothing
Set olkNameSpace = Nothing
Set olkApp = Nothing

End Sub
 
Thank you so much. This worked great. Answer to a prayer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top