?
Solved

Create an Outlook Rule to generate a SQL Server action

Posted on 2008-06-23
5
Medium Priority
?
285 Views
Last Modified: 2011-06-22
I receive standardized messages in Outlook. When I receive the message I go into SQL Server, go to the record referenced in the Outlook message and then go to a webpage stored as a URL in the referenced record. How would I set up a rule in Outlook that would upon receipt of the message, find the keyword, open SQL Server, match the keyword to the record and open the URL?
0
Comment
Question by:bpfsr
[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: 21853926
Hi, bpfsr.

The short answer is to write a script that handles connecting to SQL server, doing the search, and launching the URL if a matching record is found.  You'd then create a rule that calls this script.  I can give you the pseudo-code for the process, but I don't have access to SQL server, so I can't provide a complete solution.
0
 

Author Comment

by:bpfsr
ID: 21855033
pseudo code would work, thank you.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 21855246
Ok.  You'll want something like this.  Here's how this will work.

1.  The rule fires and calls the script below, passing the message that triggered the rule as a parameter.
2.  The code parses the body and finds the reference to the SQL record.
3.  Create a connection to the SQL database
4.  Select the record matching the value from the message
5.  Retrieve the URL from the record
6.  Launch Internet Explorer
7.  Navigate to the URL
8.  Make IE visible
9.  Clean-up the objects to avoid memory leaks
Sub RunSQL(Item As Outlook.MailItem)
    Dim adoCon As Object, adoRS As Object, strKey As String, strURL As String, objIE As Object
    'Replace x on the next line with code to get the record reference from the message body.  I don't know what the messages look like, so I can't advise on the exact code.
    strKey = x
    Set adoCon = CreateObject("ADODB.Connection")
    'Replace Connection String on the next line with a conenction string for SQL Server
    adoCon.Open "Connection String"
    'Replace Fields, Table, and KeyField on the next line with the appropriate values
    Set adoRS = adoCon.Execute("SELECT Fields FROM Table WHERE KeyField = '" & strKey & "'")
    If (Not adoRS.bof) & (Not adoRS.EOF) Then
        'Replace URL_Field_Name on the next line with the name of the field in the database that holds the URL
        strURL = adoRS.Fields("URL_Field_Name").Value
        Set objIE = CreateObject("IntenetExplorer.Application")
        objIE.Navigate2 strURL
        objIE.Visible = True
    End If
    Set objIE = Nothing
    adoRS.Close
    Set adoRS = Nothing
    adoCon.Close
    Set adoCon = Nothing
End Sub

Open in new window

0
 

Author Comment

by:bpfsr
ID: 21975485
Hello,
Sorry it took so long to come back but I moved last week which put a crimp in - well - everything! Anyhow, I looked at your code and it does make sense to me. I have two questions:
1. When I create the rule, I see the option to run a script, but it looks like Outlook wants me to select the script from a list. Where do I save the script so it gets added to the list.
2. In the beginning of the code where 'x' equals the searched for phrase, assuming "find this text" was the key phrase, would you be able to tell me how to conduct that search?

Thank you
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 21977109
Hi, bpfsr.

No problem.  I know how moving can be.

1.  Press ALT+F11 to open Outlook's VB editor.  Expand the folders on the left under Project1.  The code can go in any module except ThisOutlookSession.  It'll then appear automatically in the list of scripts available to rules.

2.  I can't answer the question.  I've no idea what the message body will look like, so there's no way for me to know what it'll take to find the key text.  
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

801 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