LOOKING AT ACCESS'S HYPERLINK FEATURES

Hyperlinks have been around for quite a while in one form or another. In help systems, hypertext is used to create “hot spots” in help files that move users to information applying to the subject they clicked.

The Internet uses hyperlinks to move from one HTML page to another, or to move from one URL to another. HTML, or Hypertext Markup Language, is the standard language used for creating World Wide Web pages. Although it sounds like something college students do after a Friday night, URL (uniform resource locator) is the standard method for addressing various locations on the Web.

As of Access 97, you can use hyperlinks in various forms in Access:

  • As an unbound control on a form linking to objects in the current database, current sys tem, networked computer, intranet address, or Internet address

  • As a field in a table, with a special data type, performing the same links as just mentioned

Note

Regardless of what you use to call a hyperlink and what kind of call it was, the Web toolbar appears.


You can see various examples for hyperlinks on the frmHyperlinkExamples form (see Figure 19.1), found in Chap19.mdb. This database can be found on the accompanying CD-ROM in the ExamplesChap19 folder.

Figure 19.1. This form and its subform contain bound and unbound hyperlink controls.


Tip

As of Access 2000, you can now add Screen Tips to your Hyperlink. You can see this for the hyperlink for Applications Plus (my company), where it says “Check out the author's home page!” Adding Screen Tips is discussed later in this chapter in the section “Editing the Hyperlink Properties.”


Working with Unbound Hyperlink Controls

Access has three different control types that can be hyperlink enabled, giving you various methods for using hyperlinks in your application: label, image, and command button. You find that each control now has two new properties—Hyperlink Address and Hyperlink SubAddress. You can see these properties in the property sheet (see Figure 19.2) or in the Edit Hyperlink dialog (shown later in Figure 19.3).

Figure 19.2. By filling in the Hyperlink Address property, you can link to a URL or a path and filename of another application, as well as other protocols.


Figure 19.3. I typed this URL for the Integrated Visual Concepts home page on the Internet.


Using the Hyperlink Address and Hyperlink SubAddress

The Hyperlink Address is where you place the address of what you want linked. This address can be any of the following protocols:

\ (UNC path) msn:
cid: news:
file: nntp:
ftp: pnm:// (Real Audio Media)
gopher: prospero:
http: rlogin:
mailto: telnet:
mid: tn3270:
mms:// (Microsoft MediaServer media) wais:

Note

The UNC (Universal Naming Convention) path is the absolute path used with Windows NT network servers. Suppose that the VidApp.mdb database is in the Examples folder and is assigned to the logical H: drive. The H: drive is assigned the share \AbednegoRoot. The UNC path would be

\AbednegoRootExamplesVidApp.mdb


Use the Hyperlink SubAddress property to specify the object in the file you want to use. An example here could be a form within VidApp.mdb—in this case, ap_SystemUtilities. For this example, the Hyperlink SubAddress would be

Form ap_SystemUtilities

Editing the Hyperlink Properties

You can edit the Hyperlink Address and Hyperlink SubAddress properties in a number of ways. The easiest way is to right-click the hyperlink control you're interested in editing, and then choose Hyperlink and then Edit Hyperlink from the shortcut menu. This selection brings up the Edit Hyperlink dialog (see Figure 19.3) for the label control hplVisualConcepts.

This dialog has been majorly revamped in Access 2000. The first item now on the dialog is the Text to Display text box. Next is the button that leads to Screen Tips. These controls are the same regardless of which type of hyperlink you are creating.

To work through the rest of this dialog, look at the Link To list along the left side of the dialog:

  • Existing File or Web Page specifies a Web page (including World Wide Web sites) or a physical file. This is the Hyperlink Address. If the address is a file, click the Browse For buttons to locate the file on the machine's hard drive or on the network (File) or a Web Page.

    When specifying a subaddress such as a form within another database, separate the address from the subaddress with the pound sign. For instance, to open the ap_SystemUtilities form within VideoApp.mdb, the address#subaddress would be

    ..Videoapp.mdb#Form ap_SystemUtilities
    
  • Object in This Database allows you to specify an object in the current Access database. When selected, you will see the Hyperlink SubAddress—actually, a tree that displays all the objects (see Figure 19.4).

    Figure 19.4. Here, clicking Object in This Database creates a hyperlink in which the address is the current application.

  • Create New Page allows you to create a new Web page and point to it, or just specify a Web page and actually create it later.

  • E-mail Address is great for creating PIMS (Personal Information Systems). This allows you to easily specify an email address for a field.

Tip

In the Edit Hyperlink dialog, you need to use only the .. to specify that you want the address to be relative to the application. You can see this in Figure 19.5.

Figure 19.5. This hyperlink uses the path of the address relative to the location of the current application.


Use the .. whenever you have hyperlinks to subfolders beneath your application. That way, if you move your application, Access can still find the path relative to the new location.

You can also have your address relative to another path rather than your application.This property, Hyperlink Base, is discussed in the following section.


Maintaining a Hyperlink Base for a Database

As just mentioned, Access lets you specify a path as the base for your hyperlinks, other than your current application. To change the Hyperlink Base property, choose Database Properties from the File menu. Click the Summary tab to see the Hyperlink Base property at the bottom (see Figure 19.6).

Figure 19.6. Set Hyperlink Base when you want to make your hyperlinks relative to another location.


Looking at the Hyperlink Data Type

In addition to using unbound controls, there's a data type of Hyperlink. The Hyperlink data type, now added to the list of data types in Table Design view, lets you store hyperlinks within a table and lets users go to the address stored in the Hyperlink data type field.

To see this, look at the frmHyperlinkExamples form in Form view (see Figure 19.7). Notice that in the Datasheet view of the subform (on the right side of the form), the first record displays the text Microsoft's Home Page, and the second displays a URL (for Macmillan's home page).

Figure 19.7. You can create captions for hyperlinks even with the Table field of the Hyperlink data type, as seen for Joram Hughes's Favorite Home Page—Applications Plus. The hyperlink is http://www.Apps-Plus.com.


To display the caption versus the actual hyperlink address when you're adding the hyperlink to the table, place the cursor in the Hyperlink type field and then press F2. You can also add it by using the Text To Display text box in the Edit Hyperlink dialog.

Caution

When adding a hyperlink to a table, make sure that you don't click an existing hyperlink because you'll end up calling it. This causes problems if you aren't hooked up to the Web.


The other way to get in the Edit mode of a hyperlink is to right-click the field, choose Hyperlink, and then choose Select Hyperlink. You aren't taken to another dialog, but you see the actual entry into the field, separated by the pound sign (see Figure 19.8). Another way to see the entire hyperlink text is to press F2 when on the table entry.

Figure 19.8. You can see the entire hyperlink address and caption for Application Plus's Web site.


The Hyperlink type field is divided into four parts, separated by the pound sign (#):

This was done for Microsoft's home page by typing the following into the FavoriteHomePage field:

Microsoft's Home Page#http://www.msn.com#

If you're using the ap_SystemUtilities form in VidApp.mdb, you type

Utilities Form#..VidApp.mdb#Form ap_SystemUtilities#

This example showed you how to store hyperlinks into your database. It's now time to see what you can do with hyperlinks by using VBA.

Adding Hyperlinks to Your Interface by Using the IsHyperlink Property

You might find yourself using a back-end database, such as SQL Server, that doesn't support Access's Hyperlink data type. Wouldn't it be great if you could still use bound hyperlinks on your forms? In Access 2000 you can. Access 2000 text boxes and combo boxes each have a new property on the Format tab, IsHyperlink. If you set this property to Yes, Access treats the data in the field like a hyperlink—it uses the hyperlink display format, you can edit the field with the Edit Hyperlink dialog, and you can follow the link with a single click.

To see the IsHyperlink property in action, select the tblCustomersNoHyperlink table in the Database window. This table stores the FavoriteHomePage in a memo field rather than a hyperlink. With this table selected, choose AutoForm from the Insert menu. Access creates and opens the form in Figure 19.9.

Figure 19.9. The FavoriteHomePage field appears as plain text by default because it's stored in a Memo data type.


The FavoriteHomePage field now displays the raw, #-delimited data stored in the field.

Another feature new to Access 2000 is that many form properties can be modified in Page view. You might already see the form property sheet, but if not, choose Properties from the View menu. Put the cursor in the FavoriteHomePage field. On the Format page, change the IsHyperlink property to Yes. The raw text format is changed to a hyperlink, with only the display text visible, as shown in Figure 19.10. You can now click and follow this link.

Figure 19.10. The Favorite HomePage field now looks and behaves like a hyperlink.


Programmatically Using Hyperlinks with the Follow, FollowHyperlink, and HyperlinkPart Methods

When you want to go to a hyperlink's address in code, you can use one of two methods: Follow or FollowHyperlink.

Using the Follow Method

You use the Follow method when a hyperlink control or field already exists. You will use the method off the actual (hyperlink) object itself. An example of using Follow might be when a customer is using the system and requests the system to go to his recorded home page.

You can see an example of using the Follow method in Listing 19.1. This code is attached to the OnClick event of a new command button, cmdFollowHomePage, which was added to the frmHyperlinkExamples form.

Listing 19.1. Chap19.mdb: Using the Follow Method to Fire Off a Hyperlink Programmatically
Private Sub cmdFollowHomePage_Click()

   On Error GoTo cmdFollowHomePage_Error

   If Len(Me!HyperLinkExamplesSub!FavoriteHomePage.Hyperlink.Address) _
      = 0 Then
         Beep
         MsgBox "This Customer doesn't have a home page!", vbCritical, _
            "Error Occurred"
   Else
      Me!HyperLinkExamplesSub!FavoriteHomePage.Hyperlink.Follow
   End If

   Exit Sub
cmdFollowHomePage_Error:
   MsgBox Err.Description
   Exit Sub

End Sub

One Hyperlink property is used in this routine with the Follow method. Notice that the Address property and Follow method are off the Hyperlink property for the specific control being used—in this case, FavoriteHomePage. The syntax for the Follow method is as follows:

								object.Hyperlink.Follow(newwindow,addhistory,extrainfo,method,headerinfo)

The Follow method uses these optional arguments:

  • newwindow This Boolean argument specifies whether to open the document in a new window. The default is false.

  • addhistory This Boolean argument specifies whether to add the hyperlink to the history folder. The default is true.

  • extrainfo This information can be a parameter for the address, provided that it takes one.

  • method This is one of two constants: msoMethodGet (extrainfo is appended to the address and is a string) and msgMethodPost (extrainfo is posted as a string or an array of type byte).

  • headerinfo This string argument lets you specify what you want displayed in the header. By default, the string is zero-length.

In some cases, you need to allow users to specify a hyperlink on-the-fly. In that situation, you use the FollowHyperlink method, off the Application object.

Using the FollowHyperlink Method

When using the FollowHyperlink method, you supply the Address and SubAddress information in addition to some of the information used for the Follow method.

For the example here, a number of controls have been placed on the frmHyperlinkExamples form that allow users to specify the parameters used with the FollowHyperlink method. You can see these controls on the lower half of the frmHyperlinkExamples form in Figure 19.11.

Figure 19.11. The controls in the lower part of the form will be used with the FollowHyperlink method off the Application object.


Listing 19.2 shows the code for following a hyperlink.

Listing 19.2. Chap19.mdb: Following a Hyperlink
Private Sub cmdFollowHyperlink_Click()

   On Error GoTo cmdFollowHyperlink_Error

   If IsNull(txtExtraInfo) Then
      If IsNull(txtSubAddress) Then
         Application.FollowHyperlink Me!txtAddress, , _
            Me!chkNewWindow, Me!chkAddHistory, , , Me!txtHeaderInfo
      Else
         Application.FollowHyperlink Me!txtAddress, Me!txtSubAddress, _
            Me!chkNewWindow, Me!chkAddHistory, , , Me!txtHeaderInfo
      End If
   Else
      If IsNull(txtSubAddress) Then
         Application.FollowHyperlink Me!txtAddress, , _
            Me!chkNewWindow, Me!chkAddHistory, Me!txtExtraInfo, , _
            Me!txtHeaderInfo
      Else
         Application.FollowHyperlink Me!txtAddress, Me!txtSubAddress, _
            Me!chkNewWindow, Me!chkAddHistory, Me!txtExtraInfo, , _
            Me!txtHeaderInfo
      End If
   End If

   Exit Sub

cmdFollowHyperlink_Error:
   MsgBox Err.Description
   Exit Sub

End Sub

In cases such as txtSubAddress and txtExtraInfo, you need to check for null values because the FollowHyperlink method isn't very forgiving when dealing with null values.

The last things to examine with hyperlinks are the options you can set for your application that affect hyperlinks.

Using the HyperlinkPart Method

At times you might find it necessary to break raw, #-delimited hyperlink data down into its component address, subaddress, display text, and Screen Tip parts. You can easily do this with the Access Application object's HyperlinkPart method. The frmHyperlinkPartExample form in Ch19.mdb (see Figure 19.12) uses the HyperlinkPart method to perform such a breakdown.

Figure 19.12. The parts of the FavoriteHomePage field are separated in the frmHyperlinkPartExample form.


In the example, the hyperlink part fields are recalculated in the form's Current event. Listing 19.3 shows the code.

Listing 19.3. Chap19.mdb: Using the HyperlinkPart Method
Private Sub Form_Current()

    Dim strHyperlink As String

    strHyperlink = Nz(Me.FavoriteHomePage)

    'Use the HyperlinkPart function to decompose the hyperlink
    txtAddress = HyperlinkPart(strHyperlink, acAddress)
    txtDisplayedValue = HyperlinkPart(strHyperlink, acDisplayedValue)
    txtDisplayText = HyperlinkPart(strHyperlink, acDisplayText)
    txtFullAddress = HyperlinkPart(strHyperlink, acFullAddress)
    txtScreenTip = HyperlinkPart(strHyperlink, acScreenTip)
    txtSubAddress = HyperlinkPart(strHyperlink, acSubAddress)

End Sub

Most of the intrinsic constants accepted as the optional second argument to the HyperlinkPart method are self-explanatory. The default value is acDisplayedValue, which gets you the string that Access will display in the user interface. The value acFullAddress just returns the address and subaddress separated by a # sign.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.251.68