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.
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.”
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).
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
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).
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.
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.
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).
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).
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.
The Hyperlink type field is divided into four parts, separated by the pound sign (#):
Display text or caption
Address, using either a UNC or a URL, as described earlier in “Editing the Hyperlink Properties”
SubAddress, an object in a file—again, as described in the section “Editing the Hyperlink Properties”
ScreenTip, the ToolTip that appears when users hover the mouse pointer over the hyperlink
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.
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.
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.
When you want to go to a hyperlink's address in code, you can use one of two methods: Follow or FollowHyperlink.
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.
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.
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.
Listing 19.2 shows the code for following a hyperlink.
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.
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.
In the example, the hyperlink part fields are recalculated in the form's Current event. Listing 19.3 shows the code.
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.
18.226.251.68