Access Cookbook, 2nd Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Access Cookbook, 2nd Edition [Electronic resources] - نسخه متنی

Ken Getz; Paul Litwin; Andy Baron

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










Recipe 16.6 Create a Custom Smart Tag to Get a Weather Report



16.6.1 Problem


I have a call list of customer names. I'd like to
use a smart tag on the postal code field to
retrieve a weather report for that postal code so that when I make
the call, I can talk about the weather. How can I create a custom
smart tag that retrieves the weather forecast from the Internet for a
given postal code?


16.6.2 Solution


There are two different approaches to creating your own smart tags:
you can create an XML file or you can create a dynamic-link library
(DLL). Using an XML file is the best solution when you want to create
a smart tag that simply navigates to a
location on the Internet (or an intranet). Creating a
DLL is the preferred approach when your
smart tag is more complex and you need more flexibility or
conditional logic. In this example you'll learn how
to create an XML-based smart tag.

The first step is to create the XML file. This example will navigate
to the weather forecasting section of the MSNBC Web site at http://www.msnbc.com. It takes multiple mouse
clicks and typing in a zip code to find local weather conditions if
you obtain the weather forecast for a given zip code manually. Once
you get there, if you look at the URL of the local weather page after
typing in the zip code 96708, you'll see that the
URL looks like the following:

http://www.msnbc.com/news/wea_front.asp?tab=oth&czstr=96708&ta=y&accid=96708

You can create your own XML smart tag (this example is called
Weather.XML) by creating an XML file using the following format. Note
that the FL:url tag contains the revised URL with the literal zip
code replaced by {TEXT} placeholders:

<FL:smarttaglist xmlns:FL="urn:schemas-microsoft-com:smarttags:list">
<FL:name>Local Weather</FL:name>
<FL:description>Your local weather report on MSNBC.</FL:description>
<FL:moreinfourl>http://msdn.microsoft.com/office</FL:moreinfourl>
<FL:smarttag type="urn:schemas-microsoft-com:office:smarttags#weather">
<FL:caption>Local Weather Report</FL:caption>
<FL:terms>
</FL:terms>
<FL:actions>
<FL:action id="LocalWeather">
<FL:caption> -- Get Weather</FL:caption>

<FL:url>http://www.msnbc.com/news/wea_front.asp?tab=oth&amp;

czstr={TEXT}&amp;ta=y&amp;accid={TEXT}</FL:url>
</FL:action>
</FL:actions>
</FL:smarttag>
</FL:smarttaglist>


Once you've created the Weather.XML smart tag,
deploy it by copying or saving it to the following location:

\Program Files\Common Files\Microsoft Shared\Smart Tag\LISTS\

Follow these steps to use the Weather.XML smart tag in Access:

  1. Shut down any running copies of Access that may have been active when
    you saved Weather.XML to the \Smart Tag\LISTS\ folder. This is
    necessary to restart the smart tag engine.

  2. Open the Access application (

    16-06.MDB ).

  3. Open the frmCustomers form in design view. Select the PostalCode text
    box and press F4 to bring up the Properties window.

  4. Click the builder button (...) to bring up the Smart Tag dialog box
    and select the Local Weather Report option, as shown in Figure 16-8. Click OK.



Figure 16-8. Attaching the custom Weather.XML smart tag


  1. Display the form in form view, scroll through the records, and select
    the smart tag as shown in Figure 16-9. Select the
    Get Weather option and you will be redirected to the msnbc.com
    weather forecast for that zip code.



Figure 16-9. The deployed Weather.XML smart tag



16.6.3 Discussion


Here's how the Weather.XML smart tag file works:

The first line of the XML file defines a smart tag and the smart tag
list namespace. In this example, the urn:schemas-microsoft-com
namespace is used, but this is not required. You can provide any
unique namespace name that you want. You must enclose the entire
smart tag within the FL:smarttaglist element:

<FL:smarttaglist xmlns:FL="urn:schemas-microsoft-com:smarttags:list">

The next three lines define the name, description, and a URL to get
more information about the smart tag by using the <FL:name>,
<FL:description>, and <FL:moreinfourl> elements:

<FL:name>Local Weather</FL:name>
<FL:description>Your local weather report on MSNBC.</FL:description>
<FL:moreinfourl>http://msdn.microsoft.com/office</FL:moreinfourl>

The FL:smarttag element's type attribute defines a
smart tag type, which is a unique, arbitrary identifier for a smart
tag on a user's computer. The smart tag type has two
parts: the namespace URI and a tag name:

<FL:smarttag type="urn:schemas-microsoft-com:office:smarttags#weather">

The URI is conventionally some derivation of your
company's name (microsoft-com is used here), and the
tag name must consist of the "#"
symbol and some unique string (#weather). You could have the same URI
with a different tag, say #directions, the combination of which would
create a second smart tag type.

The following lines consist of the caption and terms. The caption
shows up on the smart tag (see Figure 16-9), and the
terms are not needed for Access since it does not require or support
the recognizers that are needed when working with smart tags in Word
or Excel:

<FL:caption>Local Weather Report</FL:caption>
<FL:terms>
</FL:terms>

The next text block defines the set of actions, or verbs, for the
smart tag, which is fully enclosed with an actions element. The
actions element contains one or more action child elements. This
example has a single action element consisting of a caption element
(Get Weather) and a url element, which provides the associated URL
for the action, navigating to the

www.msnbc.com Web site:

<FL:actions>
<FL:action id="LocalWeather">
<FL:caption> -- Get Weather</FL:caption>
<FL:url>http://www.msnbc.com/news/wea_front.asp?tab=oth&amp;
czstr={TEXT}&amp;ta=y&amp;accid={TEXT}</FL:url>
</FL:action>
</FL:actions>

The last two lines in the Weather.XML file close out the FL:smarttag
and FL:smarttaglist elements:

   </FL:smarttag>
</FL:smarttaglist>

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.


/ 232