Recipe 16.4 Execute a Smart Tag Action Without Displaying the Smart Tag

16.4.1 Problem

In my application I would like to use the Financial Symbol smart tag so that users will be directed to the Stock Quote on MSN MoneyCentral. I don't want to display the smart tag, which also presents two additional actions this might confuse the user. How can I configure a combo box control so that when the user selects a symbol, the Stock Quote on MSN MoneyCentral is automatically displayed in a browser window?

16.4.2 Solution

The built-in smart tags that ship with Access are somewhat limited in that they do not allow you to configure them by adding or removing actions. The Financial Symbol smart tag looks up information about a financial symbol on MSN MoneyCentral, allowing you to take the following actions:

  • Obtain a stock quote on MSN MoneyCentral.

  • Obtain a report about the company on MSN MoneyCentral.

  • Obtain recent news about the company on MSN MoneyCentral.

In Access, you enable the Financial Symbol smart tag on a field or control that contains a financial symbol the familiar abbreviations seen on stock tickers.

To execute only a single action obtaining a stock quote you need to enable smart tags in code by setting a control's SmartTags property. Once you've enabled the smart tag in your code, you can then execute a smart tag action. Once the action executes, you can then disable the smart tag so that it is never displayed to the user.

Follow these steps to configure a combo box to use the Financial Symbol smart tag to display a stock quote when the user selects an item:

  1. Create a combo box control on a form. In the sample application, the Row Source property is set to a query that selects the ticker symbol and company name from the Companies table. The Bound Column is set to the ticker symbol since that is the value that will be used for the Financial Symbol smart tag.

  2. Create an event procedure for the AfterUpdate event. This event runs after the user selects an item in the combo box. The code turns off screen painting so that setting the smart tag property will not cause screen flashing:

    Private Sub cboTickers_AfterUpdate( )     On Error GoTo HandleErr          Me.Painting = False
  3. The code then sets the financial symbol smart tag for the control:

        Me.cboTickers.Properties("SmartTags").Value = _      "urn:schemas-microsoft-com:office:smarttags#stockticker"
  4. The code then executes the first action of the smart tag. The SmartTags collection represents the smart tags assigned to the control, and SmartTagActions is the collection of available actions. You refer to them by their ordinal position in the list:

        Me.cboTickers.SmartTags(0).SmartTagActions(0).Execute
  5. Once the action has executed, remove the smart tag control so that it will never be displayed to the user:

        Me.cboTickers.Properties("SmartTags").Value = ""
  6. Whenever you turn off painting on the form, you should implement an error handler and exit label to ensure that painting gets turned back on again, even if an error occurs:

    ExitHere:      Me.Painting = True      Exit Sub       HandleErr:      MsgBox Err.Number & " " & Err.Description      Resume ExitHere End Sub

    Here is the complete code listing:

    Private Sub cboTickers_AfterUpdate( )     On Error GoTo HandleErr          Me.Painting = False          ' Set the financial symbol smart tag     Me.cboTickers.Properties("SmartTags").Value = _      "urn:schemas-microsoft-com:office:smarttags#stockticker"           ' Execute the first action listed     Me.cboTickers.SmartTags(0).SmartTagActions(0).Execute          ' Remove the financial symbol smart tag     Me.cboTickers.Properties("SmartTags").Value = ""       ExitHere:      Me.Painting = True      Exit Sub       HandleErr:      MsgBox Err.Number & " " & Err.Description      Resume ExitHere End Sub

16.4.3 Discussion

The SmartTags collection contains one or more SmartTag objects. You can refer to a single SmartTag object in the collection by using the Item method or the index. The collection is zero-based, so the following code fragment refers to the first SmartTag for the ctl control:

ctl.SmartTags(0)

Unlike in Access, the SmartTags collections in Microsoft Excel and Microsoft Word are one-based.


The SmartTag object has several properties, such as Application, IsMissing, Name and Property. The SmartTagActions property represents a collection of actions for an individual smart tag. These actions are processes that are programmed into a smart tag as individual SmartTagAction objects. The SmartTagAction object has several properties and a single method, Execute. In this example, the first SmartTagAction in the SmartTagActions collection is executed:

SmartTagActions(0).Execute

By dynamically assigning a smart tag in code, executing an action, and then removing the smart tag, you can take advantage of built-in smart tag functionality without presenting unnecessary options to the user.



Access Cookbook
Access Data Analysis Cookbook (Cookbooks)
ISBN: 0596101228
EAN: 2147483647
Year: 2003
Pages: 232

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net