Online Book Reader

Home Category

Access Cookbook - Ken Getz [316]

By Root 2093 0
number of orders for the selected customer displayed in the form's Caption. If you choose the second smart tag action, then the rptCustomers report will open displaying sales data for the selected customer.

Discussion


You can write a smart tag DLL in any language that supports writing COM add-ins. You can also write a smart tag DLL in managed (.NET) code.

There are two interfaces involved in implementing smart tag actions: the ISmartTagAction interface and the ISmartTagAction2 interface. These interfaces provide the client application with the information needed to support smart tag actions. The ISmartTagAction interface is compatible with Office XP, and the ISmartTagAction2 interface is specific to Office 2003, and allows you to tap into new functionality.

TIP

You do not need to implement the ISmartTagRecognizer and ISmartTagRecognizer2 interfaces in a smart tag DLL targeted specifically for Access because Access does not use recognizers.

The role of an ISmartTagAction interface is to provide actions for individual smart tag types. Each smart tag type is defined by a namespace URI plus its tag name to keep it unique. A "#" character is appended to the namespace URI and is used to separate the namespace URI from its tag name, as shown in this example, where "schemas-microsoft-com/smarttag/northwind" is the namespace URI and "openform" is the tag name. The combination results in the fully qualified name of the smart tag type. The URI portion of the property name ensures that it is globally unique and unambiguous, so that two tags with the same tag name (openform) can be differentiated:

Private Property Get ISmartTagAction_SmartTagName( _

ByVal ismarttag As Long) As String

ISmartTagAction_SmartTagName = _

"schemas-microsoft-com/smarttag/northwind#openform"

End Property

Working with the Access object model


The most interesting part of the sample smart tag DLL is that it shows you how you can work with the Access object model as well as DAO. The code in the ISmartTagAction2_InvokeVerb2 method has an input parameter, Target As Object, which Access uses to pass in the control that has the smart tag attached. The code then creates an Access.Control variable that references the Target:

Dim cb As Access.Control

Set cb = Target

Once you have the Access Control object, you can then set a variable to point to the Access Application object, giving you full access to any part of your application:

Dim app As Access.Application

Set app = cb.Application

From there, you can work with the data in your application by creating a DAO Database object using the Application object's CurrentDb property:

Dim db As DAO.Database

Set db = app.CurrentDb

The code goes on to open a Recordset based on a query that counts the total number of orders for the selected customer, writing it to a String variable. It then opens the form to display the selected customer and passes that count value in the OpenArgs argument of the Application object's DoCmd.OpenForm method:

app.DoCmd.OpenForm "Customers", _

WhereCondition:="[CustomerID] = '" & cb.Value & "'", _

OpenArgs:=strOrders

When the Customers form opens, the code in the Open event evaluates whether any data has been passed in the OpenArgs argument, and then displays that information in the form's Caption property. If the form is opened normally without any OpenArgs data being passed to it, then the default caption is displayed:

Private Sub Form_Open(Cancel As Integer)

Dim str As String

str = Me.OpenArgs & ""

If Len(str) > 0 Then

Me.Caption = str

End If

End Sub

The code for opening a report uses similar techniques. Creating a smart tag DLL allows you full access to the entire Access object model, and allows you to create conditional logic for your smart tag. Smart tags can be a good way to provide extra functionality for users who prefer working in datasheet view.

See Also


See the Preface for more information on working with DAO to access data .

Chapter 17. .NET


In the beginning of 2002, Microsoft introduced a new initiative called .NET that

Return Main Page Previous Page Next Page

®Online Book Reader