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!

Insert email address from textbox into "To:" field in Outlook 1

Status
Not open for further replies.

chris6976

Technical User
Mar 4, 2003
28
GB
Hi All

This is a simple query I'm sure, but I just cant quite get it!

I wish to be able to click on a customers email addy in a form and then automatically open a new email message in Outlook with that email address in the To: field.

I have the basic macro RunApp opening the Outlook program, but wish to take it that next step.

Many Thanks

Chris
 
see thread702-396121 and nathan's answer for Access/Outlook automation which will solve your problem most efficiently. Post back here if you have any questions.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Hi

Unfortunately Nathan's solution has not worked as yet. Access 2000 does not recognise objOutlook as an object.
I am also imagining that as it is not in the objects list, that objEmail is not recognised either.

Any further advice would be gratefully received either to fix the code, or add the above objects to the object list.

Chris
 
See Aubs010 (TechnicalUser)responce in thread "thread702-711153", he uses mailto for the email address from a form to appear in the "To:" field.
 
See if this code can help you. It works great for me. Note that you will have to include the reference to Microsoft Outlook 9.0 Object Library. This is using Access 2000.

Code:
Public Sub SendEmail()

    Dim oLapp As Outlook.Application
    Dim oItem As Outlook.MailItem
    
    Set oLapp = CreateObject("Outlook.Application")
    Set oItem = oLapp.CreateItem(0)
        
    With oItem
        .Subject = "Enter subject here"
        .To = "Enter email address here"
        .Body = "Enter body text here"
        
        .Send
        
    End With

    Set oLapp = Nothing
    Set oItem = Nothing
    
    ' Open Outlook and give it focus
    Shell "Outlook", 1
    
End Sub
 
Back again!

I am having trouble with the section to open Outlook. I am assuming the code:

Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(olMailItem)

opens Outlook as it would appear normally, with a blank email item ready as well.

When I debug the program:

objOutlook ="Outlook" and objEmail = "", but no applications 'opening' as it where.

I am sure it is just a tweak here or there....a solution as opposed to a link back to Nathans thread would be mucho appreciated! (Unless you are Nathan!!!!)

Thanks all
 
You will not see outlook "open".....this automated version runs in the background, hidden from view. I know there is a way to make the message visible before sending, I just don't remeber it off the top of my head.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
I would really prefer the message to be visible before sending, i.e. opening the application "as normal".

It is not a standard email that would be sent, so automation would be unsuitable.

Any other ideas anybody?
I can get Outlook to run from a macro, which is simple, but does anyone know how to open a new MailItem and insert the relevant email addy this way??

Cheers
 
chris....see the below code. Noticed I commented out the .Send line and added a .Display(True) line...this line will cause the mail to be displayed and the code to pause until the mail is sent. This should fit your needs pretty well.

Code:
Public Sub SendMyMail()

'******begin code******
Dim email, ref, origin, 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 = "test"
ref = "This"
origin = "out"
destination = "destination"
notes = "this test message"

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

'***creates and sends email
With objEmail
    .To = email
    .Subject = ref & " " & origin & " " & destination
    .Body = notes
    '.Send
    .Display (True)
End With

'**closes outlook
Set objEmail = Nothing
objOutlook.Quit

End Sub
[\code]

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Many Thanks mstrmage et Al!!!!

Its surprising what a .Display can do !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top