Class Hyperlink (Access VBA)

The Hyperlink object represents a hyperlink associated with a control on a form, report, or data access page. To use a Hyperlink class variable it first needs to be instantiated, for example

Address

You can use the Address property to specify or determine the path to an object, document, webpage, or other destination for a Hyperlink object associated with a command button, image control, or label control.

When you set the Address property, you automatically specify the HyperlinkAddress property for the control associated with the hyperlink. For more information about hyperlink addresses and their format, see the Hyperlink.SubAddress property topic.


CreateControl.Hyperlink.Address =

AddToFavorites

The AddToFavorites method adds a hyperlink address to the Favorites folder.

When applied to a Control object, the AddToFavorites method adds the hyperlink address contained in a control to the Favorites folder.


Private Sub Form_Load() 
 Me!Command0.HyperlinkAddress = "https://www.microsoft.com/" 
End SubPrivate Sub Command0_Click() 
 Me!Command0.Hyperlink.AddToFavorites 
End Sub

CreateNewDocument

You can use the CreateNewDocument method to create a new document associated with a specified hyperlink.

The CreateNewDocument method provides a way to programmatically create a document associated with a hyperlink within a control.

CreateNewDocument (FileName, EditNow, Overwrite)


Private Sub GenerateReport_Click() 
 ActiveControl.Hyperlink.CreateNewDocument _ 
 "C:\Report.txt", EditNow:=True, Overwrite:=True 
End Sub

Arguments

The following arguments are required:

FileName (String) - The name and path of the document. The type of document format that you want to use can be determined by the extension used with the file name to output the data. You can create the following: HTML (*.htm) Microsoft Active Server Pages (*.asp) Microsoft Excel (*.xls) Microsoft IIS (*.htx, *.idc) MS-DOS Text (*.txt) Rich Text Format (*.rtf) Modules can be output only to MS-DOS text format. Microsoft Internet Information Server and Microsoft Active Server formats are available only for tables, queries, and forms.

EditNow (Boolean) - True opens the document in Design view, and False stores the new document in the specified database directory. The default is True.

Overwrite (Boolean) - True overwrites an existing document if the FileName argument identifies an existing document, and False requires that the FileName argument specify a new file name. The default is False.

EmailSubject

You can use the EmailSubject property to specify or return the email subject line of a hyperlink to an object, document, webpage, or other destination for a command button, image control, or label control.

When you move the cursor over a command button, image control, or label control whose HyperlinkAddress property is set, the cursor changes to an upward-pointing hand. Choosing the control displays the object or webpage specified by the link. To open objects in the current database, leave the HyperlinkAddress property blank and specify the object type and object name that you want to open in the HyperlinkSubAddress property by using the syntax objecttype objectname. If you want to open an object contained in another Microsoft Access database, enter the database path and file name in the HyperlinkAddress property and specify the database object to open by using the HyperlinkSubAddress property. The HyperlinkAddress property can contain an absolute or a relative path to a target document. An absolute path is a fully qualified URL or UNC path to a document. A relative path is a path related to the base path specified in the Hyperlink Base setting in the DatabaseName Properties dialog box (available by choosing Database Properties on the File menu) or to the current database path. If Access can't resolve the HyperlinkAddress property setting to a valid URL or UNC path, it will assume that you've specified a path relative to the base path contained in the Hyperlink Base setting or the current database path.


CreateControl.Hyperlink.EmailSubject =

Follow

The Follow method opens the document or webpage specified by a hyperlink address associated with a control on a form or report.

The Follow method has the same effect as choosing a hyperlink. You can include the Follow method in an event procedure if you want to open a hyperlink in response to a user action. For example, you may want to open a webpage with reference information when a user opens a particular form. When you use the Follow method, you don't need to know the address specified by a control's HyperlinkAddress property. You only need to know the name of the control that contains the hyperlink. Conversely, when you use the FollowHyperlink method, you need to specify the address for the particular hyperlink that you wish to follow.

Follow (NewWindow, AddHistory, ExtraInfo, Method, HeaderInfo)


Private Sub Form_Load() 
    Dim ctl As CommandButton 
 
    Set ctl = Me!Command0 
    With ctl 
        .Visible = False 
        .HyperlinkAddress = "https://www.microsoft.com/" 
        .Hyperlink.Follow 
    End With 
End Sub

Arguments

Optional arguments

The following arguments are optional

NewWindow (Boolean) - True (1) opens the document in a new window and False (0) opens the document in the current window. The default is False.

AddHistory (Boolean) - True adds the hyperlink to the History folder and False doesn't add the hyperlink to the History folder. The default is True.

ExtraInfo (String) - A string or an array of Byte data that specifies additional information for navigating to a hyperlink. For example, this argument may be used to specify a search parameter for an .ASP or .IDC file. In your web browser, the ExtraInfo argument may appear after the hyperlink address, separated from the address by a question mark (?). You don't need to include the question mark when you specify the ExtraInfo argument.

Method (Office.MsoExtraInfoMethod) - An MsoExtraInfoMethod constant that specifies how the ExtraInfo argument is attached. The default is msoMethodGet.

HeaderInfo (String) - Specifies header information. By default, the HeaderInfo argument is a zero-length string (" ").

ScreenTip

You can use the ScreenTip property to specify or determine the text that is displayed when you move the cursor over a hyperlink control.

When you move the cursor over a hyperlink control whose HyperlinkSubAddress property is set, Microsoft Access changes the cursor to an upward-pointing hand and displays the text string defined by the ScreenTip property. Choosing the control displays the object or webpage specified by the link. For more information about hyperlink addresses and their format, see the Hyperlink.Address and Hyperlink.SubAddress property topics.


Forms("Order Entry").Controls("HomePage").Hyperlink.ScreenTip = "Go to Home page"

SubAddress

You can use the SubAddress property to specify or determine a location within the target document specified by the Address property.

The SubAddress property can be an object within a Microsoft Access database, a bookmark within a Microsoft Word document, a named range within a Microsoft Excel spreadsheet, a slide within a Microsoft PowerPoint presentation, or a location within an HTML document. The SubAddress property represents the HyperlinkSubAddress property of a named location within the target document specified by the HyperlinkAddress property. When you move the cursor over a command button, image control, or label control whose HyperlinkSubAddress property is set, the cursor changes to an upward-pointing hand. Clicking the control displays the object or webpage specified by the link. For more information about hyperlink addresses and their format, see the Hyperlink.Address property topic.


With Forms("Suppliers").Controls("Label20").Hyperlink 
 .Address = "PostalOperations.mdb" 
 .SubAddress = "Form Mailing List" 
End With

TextToDisplay

You can use the TextToDisplay property to specify or determine the display text for a hyperlink.


Forms.Item("Suppliers").Controls.Item("Label20").Hyperlink. _ 
 TextToDisplay = "Go to Home page"