Solved

Send Outlook message to SQL server via toolbar button

Posted on 2007-11-13
5
249 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Resolve DNS query failed errors for Exchange
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
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 Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

808 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