Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Wednesday, September 30, 2015

Hyperlink Opens Objects from Another Database

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.

  1. Create a new Blank Form.
  2. Insert a Label control on the Form.
  3. 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.

  4. 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.

  5. Change the Caption Property value of the Label to Open Report.
  6. Save the Form, with the Label control's Hyperlink SubAddress value set with the above changes.
  7. 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.

  1. Open your Form and create a second Label control on it.
  2. Display the property sheet of the label control.
  3. Change the Caption property value to Open Word Doc.
  4. Set the Hyperlink Address property value with the full pathname of a Word Document on your computer, like C:\My Documents\Letter.doc
  5. Save the Form with the changes.
  6. 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:

  1. 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.

  2. Select Database Properties.

  3. Select the Summary Tab.
  4. Type C:\My Documents\ in the Hyperlink Base control (see the image given above)  and click OK to save it.
  5. Open your Form and remove the C:\My Documents\ text typed in for an earlier example, leaving the Letter.doc file name intact.
  6. Save the Form and click on the label control to open the Word Document.
  7. 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.

  1. First, remove the text from the Hyperlink Base control ('C:\My Documents\') and leave the control empty.
  2. Create another Label control on your Form.
  3. Change the Caption Property value to Ext. Database.
  4. Set the Hyperlink Address property value to your external database path, like C:\mdbs\myDatabase.accdb.
  5. Set the Hyperlink SubAddress property value to Report myReport. Change the report name to match yours.
  6. Save the Form with the change.
  7. 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.

Powered by Blogger.