Access Cookbook - Ken Getz [308]
Follow these steps to add the Person and Date smart tags to the LastName field in the Employees table:
Open the Employees table in the sample application in design view.
Select the LastName Field and click the builder button to the right of the Smart Tags property at the bottom of the General tab.
Select the Person Name and Date checkboxes in the Smart Tags dialog box and click OK. This will create the following entry in the Smart Tags property, where the smart tags are listed in a semicolon-delimited string:
"urn:schemas-microsoft-com:office:smarttags#date";
"urn:schemas-microsoft-com:office:smarttags#PersonName"
Click to the left of the Smart Tags property, and you will see another smart tag, which when expanded includes the option Update Smart Tags everywhere LastName is used. Select this option, and select any existing forms you wish to inherit the new smart tags. In this example, frmEmployees can inherit the smart tags.
Save the table and view it in datasheet view. Figure 16-4 shows the Date smart tag menu displayed for the Last Name field.
Figure 16-4. Multiple smart tags are displayed with flyout menus
Open frmEmployees. You should see both smart tags displayed when you click in the LastName control.
Click the New Object: AutoForm button on the toolbar to create a new form based on the table. Note that the Last Name TextBox has inherited the smart tag. Open the existing form and note that the smart tag property is also displayed.
Discussion
When you create a smart tag on a table, Access gives you the ability to propagate the smart tag to any new forms that you may create. You can also propagate the smart tag to any forms that you may have created prior to creating the smart tag.
If you delete the smart tag from the table and do not select the "Update Smart Tags everywhere" option, then form smart tags that were inherited from table smart tags will not be deleted. Make sure that you select the "Update Smart Tags everywhere" option if you want inherited smart tags to be removed from the forms as well as the table.
16.3. Display Smart Tags when Application Starts
Problem
My application makes extensive use of smart tags. Since this is a global setting, some users may have turned off the display of smart tags. How can I ensure that smart tags are displayed when my application starts up?
Solution
The display of smart tags is controlled by a checkbox in the Tools → Options dialog box under the Forms/Reports tab. These settings apply to Access as a whole, and once changed, take effect for all running applications. Figure 16-5 shows the dialog box with the display of smart tags turned on.
Figure 16-5. Setting smart tag viewing options
The best place to set options for your application is in a startup form, which can run code to ensure that settings are the way you need them to be. The sample application is configured to use a form named frmStartup, by setting the Display/Form Start Page property in the Tools → Startup dialog box, as shown in Figure 16-6.
Figure 16-6. Configuring a startup form
Follow these steps in your startup form to ensure that smart tags are displayed for your application:
Create a variable in the declarations section of the form that you will use to retrieve and store the user's current settings. Options controlled by checkboxes return either True or False. However, retrieving and setting options in code requires the Variant data type, not a Boolean, as you might expect.
Option Explicit
Private varSmartTagOn As Variant
In the form's Open event, retrieve the user's current settings using the GetOption method. If smart tags are not turned on, then use SetOption to turn them on. The sample application collects the user's name using the