Solved

Send Outlook message to SQL server via toolbar button

Posted on 2007-11-13
5
247 Views
Last Modified: 2010-04-08
I want to create a toolbar button in Outlook that will allow me to take a highlighted e-mail in Outlook and pass the body and subject of the message to a Web form?

I am currently copying and pasting the content into the form fields and I want to now automate this process.

Thanks
0
Comment
Question by:xactdesign
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 20275823
Hi, xactdesign.

There are several ways to do this.  You could do it through a web service or you could write directly to the SQL database using something like ADO.  
0
 
LVL 2

Author Comment

by:xactdesign
ID: 20276422
OK.  I would preferably like to do it through ADO but I need a way to associate the e-mail to a customer prior to inserting the record.  I felt that passing it to a Web form and then selecting the customer from a drop down would be easiest.  I really don't care how I get there, I am just trying to eliminate copying and pasting these e-mails into text fields.

The SQL server is on a remote host, not local.  This is another reason for wanting to send the message body and subject to a form on my Web site and then submitting it.

I would appreciate some examples of how to accomplish this, that would help me so much.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 20277213
This will do the job.  You can run it from inside Outlook.

Sub FillFormFields()
    Dim objIE As Object, _
        objField1 As Object, _
        objField2 As Object, _
        olkMsg As Outlook.MailItem
    'Get the currently selected message in Outlook
    Set olkMsg = Application.ActiveExplorer.Selection(1)
    'Create an instance of IE
    Set objIE = CreateObject("InternetExplorer.Application")
    'Open the web page.  Change the URL as needed.
    objIE.Navigate2 "http://company.com/pagename.asp"
    Do Until objIE.readyState = 4
        DoEvents
    Loop
    'Get the two fields you want to fill in on the web page.  Change the field names as needed.
    Set objField1 = objIE.Document.getElementById("FieldName1")
    Set objField2 = objIE.Document.getElementById("FieldName2")
    'Fill the fields in with data from the mailitem
    objField1.Value = olkMsg.Subject
    objField2.Value = olkMsg.Body
    'Display IE
    objIE.Visible = True
    'Clean-up
    Set objIE = Nothing
    Set objField1 = Nothing
    Set objField2 = Nothing
End Sub
0
 
LVL 2

Author Comment

by:xactdesign
ID: 20277380
Hey thanks for the code.

When I run the code in Outlook I get the following error:

Runtime Error 91

Object variable or with bloack variable not set

on this line
 objField1.Value = olkMsg.Subject
0
 
LVL 2

Author Comment

by:xactdesign
ID: 20277471
Nevermind, I forgot to upload my web page.  It worked great.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now