Online Book Reader

Home Category

Access Cookbook - Ken Getz [309]

By Root 2012 0
InputBox function and displays it in a label control that has the Person Name smart tag attached:

Private Sub Form_Open(Cancel As Integer)

' Retrieve user's SmartTag settings

varSmartTagOn = Application.GetOption( _

"Show Smart Tags on Forms")

' Display smart tags if needed

If Not varSmartTagOn Then

SetOption "Show Smart Tags on Forms", True

End If

lblName.Caption = InputBox( _

"Type your name:", "Welcome Message", "")

End Sub

In the form's Close event, reset the user's smart tag options to their original values:

Private Sub Form_Close( )

' Restore user's smart tag option setting

Application.SetOption "Show Smart Tags on Forms", varSmartTagOn

End Sub

Discussion


By saving the smart tag settings in a variable, you can ensure that your application behaves in a polite way, only changing the user's global settings that are needed for your application to function properly. In the sample application, the code in the Close button event handler closes the form and resets the user's smart tag options to whatever they were when the application opened. You could elect to simply hide the form instead:

Private Sub cmdClose_Click( )

Me.Visible = False

End Sub

The code in the form's Close event will not execute if the form is hidden and not closed. When the application shuts down, the form closes and the code in its Close event runs and resets the user's smart tag options to their original values.

The frmStartup form in the sample database also contains a Toggle Smart Tags button that toggles the display of the smart tags option. The ToggleShowSmartTags procedure reverses the current option settings for displaying smart tags and stores the new setting in the varSmartTagOn variable:

Private Sub ToggleShowSmartTags( )

' Toggle smart tag settings

varSmartTagOn = Not varSmartTagOn

Application.SetOption "Show Smart Tags on Forms", varSmartTagOn

MsgBox "Application Settings = " & varSmartTagOn, , "Show Smart Tags"

End Sub

You can test the code by opening frmStartup and frmTest side by side. You can see the smart tags on both forms enabled or disabled as you click the Toggle Smart Tags button on frmStartup.

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


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?

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:

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.

Create an event

Return Main Page Previous Page Next Page

®Online Book Reader