Access Cookbook - Ken Getz [310]
Private Sub cboTickers_AfterUpdate( )
On Error GoTo HandleErr
Me.Painting = False
The code then sets the financial symbol smart tag for the control:
Me.cboTickers.Properties("SmartTags").Value = _
"urn:schemas-microsoft-com:office:smarttags#stockticker"
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
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 = ""
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
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)
TIP
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.
16.5. Create a Smart Tag on a Table in an Access Project
Problem
I would like to create a smart tag on a table in my Access Project (.adp). When I open the SQL Server table in the table designer in my Access project, I do not see the smart tag property, although it is listed for controls in the Forms designer.
Solution
In SQL Server, the smart tag property has to be set as an extended property since it is not one of the standard SQL Server table properties. This requires that you run SQL Server's built-in sp_addextendedproperty system stored procedure to add it as an extended property. The syntax shown in SQL Server Books Online for sp_addextendedproperty is not that easy to figure out, as you can see from this listing:
sp_addextendedproperty
[ @name = ] { 'property_name' }
[ , [ @value = ] { 'value' }
[ , [ @level0type = ] { 'level0_object_type' }
, [ @level0name = ] { 'level0_object_name' }
[ , [ @level1type = ] { 'level1_object_type' }
, [ @level1name = ] { 'level1_object_name' }
[ , [ @level2type = ] { 'level2_object_type' }
, [ @level2name = ] { 'level2_object_name' }
]
]
]
]
Follow