Solved

Send Outlook message to SQL server via toolbar button

Posted on 2007-11-13
5
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Changing a few Outlook Options can help keep you organized!
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

752 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