Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Send Outlook message to SQL server via toolbar button

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
xactdesign
Asked:
xactdesign
  • 3
  • 2
1 Solution
 
David LeeCommented:
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
 
xactdesignAuthor Commented:
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
 
David LeeCommented:
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
 
xactdesignAuthor Commented:
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
 
xactdesignAuthor Commented:
Nevermind, I forgot to upload my web page.  It worked great.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now