Online Book Reader

Home Category

Access Cookbook - Ken Getz [313]

By Root 1846 0
elements:

Although easy to create, the XML file approach can't do much other than open a web site. One advantage of this technique is that you can update the XML file on the user's computer without having to rewrite your application or reinstall any components.

16.7. Create a Custom Smart Tag DLL


Problem


Users of my application prefer to use datasheet view for browsing data. I'd like to provide a smart tag that will enable them to open forms and reports. How can I create a custom smart tag that will allow users to open a form that shows all orders for a customer as well as open a report that shows total sales for a customer?

Solution


If you want to provide conditional processing for smart tag actions then you must create a smart tag DLL, using Visual Basic 6.0 or Visual Basic .NET. In this solution, you'll see how you can use Visual Basic 6.0 to accomplish this.

TIP

If you prefer, you can use Visual Basic .NET to create the smart tag DLL. In Chapter 17 you'll learn how to create .NET programs that can be called by Access. For smart tags, there is no particular advantage to using Visual Basic .NET and Visual Basic 6.0 will be more familiar to Access programmers who have worked with VBA, so we have chosen to use Visual Basic 6.0 for this example.

Setting up the DLL project


Follow these steps to create the DLL project using Visual Basic 6.0:

Launch Visual Basic 6.0 and create a new DLL project. The sample application is named AccessSmartTag, and it includes one class, stActions. The stActions class provides the Actions interface that defines the smart tag actions you want to take.

Add the references shown in Figure 16-10. The reference to the Microsoft Smart Tags 2.0 Type Library is required. This example also has a reference to the Microsoft Access 11.0 Object Library so that you can work with Access objects from your smart tag code and the Microsoft DAO 3.6 Object Library so that you can work with data objects.

Figure 16-10. Setting references to the Microsoft Smart Tags 2.0 Type Library, the Access 11.0 Object Library, and the Microsoft DAO 3.6 Object Library

Place the following statements in the Declarations of the stActions class. You do not need a Recognizer interface for a smart tag that is designed to work exclusively with Access:

Option Explicit

Implements ISmartTagAction

Implements ISmartTagAction2

The next step is to implement the smart tag action interface by creating properties and methods that describe the smart tag action DLL. Most of these properties are fairly straightforward and just return a requested string. The ISmartTagAction_ProgId( ) is the language-independent unique identifier that corresponds to the ProgID of the DLL class. In this example, the name of the project is AccessSmartTag, and the class name is stActions:

Private Property Get ISmartTagAction_ProgId( ) As String

ISmartTagAction_ProgId = "AccessSmartTag.stActions"

End Property

The ISmartTagAction_Name property is a short phrase that describes the DLL:

Private Property Get ISmartTagAction_Name(ByVal lcid As Long) As String

ISmartTagAction_Name = "Demo Smart Tag Actions"

End Property

The ISmartTagAction_Desc property is a longer description of the DLL:

Private Property Get ISmartTagAction_Desc(ByVal lcid As Long) As String

ISmartTagAction_Desc = _

"This is a Sample SmartTag used to open Forms and Reports."

End Property

The ISmartTagAction_SmartTagCount property reflects the number of smart tag types. This example contains one smart tag, so the count is 1:

Private Property Get ISmartTagAction_SmartTagCount( ) As Long

ISmartTagAction_SmartTagCount = 1

End Property

Each smart tag type is defined by a namespace to keep it unique, which is defined in the ISmartTagAction_SmartTagName property. SmartTag type names are always in the format of namespaceURI#tagname. In this example, the (ismarttag = 1) condition isn't strictly necessary since there is only one smart tag type defined, but this shows a pattern you could use

Return Main Page Previous Page Next Page

®Online Book Reader