Introduction.
Hyperlinks in Microsoft Access are an excellent tool to open internal or external objects very easily, without writing macros or VBA Code. Hyperlink Address and Hyperlink SubAddress properties are available on Label controls, Command Buttons, and Image controls.
We have already looked into a few examples earlier, dealing with hyperlinks. Links to those articles are given at the end of this page for reference.
If you have not yet tried anything with these properties of the above controls, then let us go straight into a demo run and learn the usage of both these properties.
The Sample Trial Run.
- Create a new Blank Form.
- Insert a Label control on the Form.
- While the label control is still in the selected state display its Property Sheet (F4).
Note: Hyperlink Address and Hyperlink SubAddress Properties are used for different purposes.
- Hyperlink Address: for opening external objects, like Word Documents, Excel Worksheets, .PDF files, etc.
- Hyperlink SubAddress: for opening internal objects, like Forms, Reports, Tables, Queries, and Macros.
Let us open a Report from your database using the Hyperlink SubAddress property setting.
- Find the Hyperlink SubAddress property and write the following text into it:
Report <Your Report Name>
Replace <Your Report Name> text with one of your own report names (without the < > brackets). The correct format for writing a value into this property is <Object Type> i.e. Form, Report, Table, Query, or Macro followed by a space, followed by the actual object name.
- Change the Caption Property value of the Label to Open Report.
- Save the Form, with the Label control's Hyperlink SubAddress value set with the above changes.
- Open the Form in normal view and click on the label control.
You will see how your report is open in Print Preview.
Opening an Excel or Word File.
Now, let us try to open an MS-Word Document using the other property, the Hyperlink Address setting.
- Open your Form and create a second Label control on it.
- Display the property sheet of the label control.
- Change the Caption property value to Open Word Doc.
- Set the Hyperlink Address property value with the full pathname of a Word Document on your computer, like C:\My Documents\Letter.doc
- Save the Form with the changes.
- Open the Form in normal view and click on the second label to open the Document in MS Word.
Note: You can open Web pages by setting the Hyperlink Address property value to a web address: say https://www.msaccesstips.com
The HyperLink Base.
If your external files, which you plan to open in Access, are all in one location C:\My Documents\ then you don’t need to duplicate it in every control but to specify the Path (C:\My Documents\) at one place: Hyperlink Base and only needs to write the document name (like Letter.doc or any other file on that location) in the Hyperlink Address property.
Let us try that:
Click on the Office Button at the left top corner and highlight the Manage option to display Database options (Access 2007). In Access 2003 and earlier versions, you will find this option in Tools Menu.
Select Database Properties.
- Select the Summary Tab.
- Type C:\My Documents\ in the Hyperlink Base control (see the image given above) and click OK to save it.
- Open your Form and remove the C:\My Documents\ text typed in for an earlier example, leaving the Letter.doc file name intact.
- Save the Form and click on the label control to open the Word Document.
- You may try to open any other document you have in that location, with only the file name change in the label.
Opening Objects from another Microsoft Access Database.
If you have followed me so far with the above sample exercises, then with a few changes we can do it.
- First, remove the text from the Hyperlink Base control ('C:\My Documents\') and leave the control empty.
- Create another Label control on your Form.
- Change the Caption Property value to Ext. Database.
- Set the Hyperlink Address property value to your external database path, like C:\mdbs\myDatabase.accdb.
- Set the Hyperlink SubAddress property value to Report myReport. Change the report name to match yours.
- Save the Form with the change.
- Open the Form in normal view and click on the label control.
Your external database will open first and will show your report in print preview.
Note: If your database is secured, then it will prompt for User ID and Password. You may try to open other objects: Form, Query, Macro & Table.
No comments:
Post a Comment
Comments subject to moderation before publishing.