Introduction
We have seen in the previous example that all our Forms can be organized in one place with the use of a ListBox and can Open the Form by Double_Clicking an item in the list. Based on the value in the Type field of the control table, a Form/Report opens directly or runs a macro to perform a sequence of operations to prepare the output before opening a Form with the processed data linked to the Form.
The objective of this method that we are going to try out here is the same, but we can do it very easily and differently. It is better to know more than one method for a task which we can use in our various projects, rather than using the same thing everywhere.
Continuous Form to look like a List.
For this example, we need to design a small form (not a Listbox) and make it look like a Listbox.
First, create a table with two fields with the following field Types and sizes:
Field Name | Type | Size |
Seq | Number | Integer |
Desc | Hyperlink | |
Save the table with the Name: DataFiles2. Open the Table to add a few records to it. In MS-Access 2003 we have a problem entering Hyperlink SubAddress of Objects from within the Database. But we can use more than one trick to beat this problem. First, you must know how the Hyperlink data is stored within the Hyperlink field. The data is stored in a Four segment format, separated by the # symbol.
Hyperlink Address in 4 Segments
Syntax:
Display Text # External File's Hyperlink Address # Internal Objects Hyperlink SubAddress # Control Tip Text
You can use the last segment to display some helpful text when you point to the Hyperlink. We will ignore this segment here.
Right-clicking on the Hyperlink Field displays the Hyperlink Shortcut Menu and pointing to it will display the Edit Hyperlink option, select it. This is the same menu you have opened from the Hyperlink SubAddress property of the command Button to Link a Macro in Closing Forms Example. But the Dialogue Control displayed here doesn't have the Object in this Database option in the Link To list. You cannot browse to the database object to link its name directly into the Hyperlink field. But, you can use this dialogue box to enter data into the field.
- Type a Descriptive Text in the Text to Display box on the top of the dialog control.
- Type a hash symbol (#) followed by the type of object name (like Form, Report, etc.) you are linking followed by the name of the Object itself after giving space between the type and the Name in the Address: box at the bottom.
Example-1:
- Text to Display: Edit Employees' Data
- Address: #Form Employees
Click the OK button. The 'Edit Employees Data' text only will be displayed in the Hyperlink field of the table. When you click on the field the Employees Form will open.
Example-2:
You can achieve the same result by typing a 3-segment Hyperlink value in the table Desc field directly:
Edit Employees' Data##Form Employees
You need to insert two hashes (#) symbols between the Text to Display & the Hyperlink SubAddress segments to open an object from within the Database. The Object Type, like Form, Report, Macro, and Table must be specified immediately after the 2nd hash symbol, followed by the Object name itself after giving space between them.
If you need to open an external file like a Word-File you can type the full path of the File like C:\My Documents\mywordfile.doc immediately after the first hash symbol. In that case, the third segment is not required, if entered, it will be ignored.
Approaching Edit a Hyperlink field is a tricky business. When you point to the arrow key the field is ready to click and open the link not to facilitate editing. So selecting the field for editing is like catching a snake without getting a snakebite. You can approach the task in two ways.
- Point the mouse pointer on the field and move towards the intersection of the left side field (if there is one) the pointing hand will change into a 3D + sign. At that point click the field to select the Hyperlink Field.
- Another method is to right-click on the Hyperlink field which will highlight the field and open the shortcut menu. Click outside somewhere to remove the shortcut menu displayed.
After selecting the Hyperlink field you can edit the contents by using the Example-2 method explained above.
Enter a few more records in the DataFiles2 Table to open the Objects of your choice by entering their Object Type and Name correctly in the Hyperlink SubAddress segment and close the Table.
Now we need to design a small form. Click the Table and select Form from the Insert Menu and select AutoForm: Tabular from the New Form Wizard and click Ok. A tabular form is created and opened in the data view. Close the form and save it with the Name: DataFiles2. Open the form in the design view to change its properties to look like a Listbox.
- Click the View menu and remove the checkmark from the Form Header/Footer item. This action will display a warning message, click Yes to remove the Header & Footer Sections of the Form.
- Click on the left top corner of the form where the left-side and top scales meet, where a black square shows at the intersection, to select the Form rather than its controls.
- Press the Alt+Enter keys or Click Properties from the View menu to display the Form's property sheet.
- Change the following Form Properties:
- Allow Datasheet View: No
- Allow Additions: No
- Allow Deletions: No
- Data Entry: No
- Scroll Bars: Neither
- Record Selectors: No
- Navigation Buttons: No
- Dividing Lines: No
- Border Style: None
- ControlBox: No
- Min Max Buttons: None
- Close Button: No
- Click on the Detail Section of the form and display the Property Sheet.
- Change the Back Color Property Value to 128 (will change to dark red color)
- Select the Seq Field control and change its width property to 0.2'
- Select Seq & Desc text boxes together, and select Align - - > Left from the Format menu, which will bring the controls close together.
- Select Shortest from the Format - - > Size Option to change both controls' height to the same value.
- Now change the Properties (still both controls selected) of the controls to the following values:
- Special Effect: Flat
- Top: 0
- Back Color: 128
- ForeColor: 16777215
- Resize the form's detail section close to the field sizes using the sizing handles at the right and bottom edges of the form. Change both control's border Color & Font weight:
- Border Color: 128
- Font Weight: Bold
- Select the Seq field alone and change the following properties too:
- a. Enabled: No
- b. Locked: Yes
The completed form in the design view will look like the sample given below:
When opened in Form View, it will look like the sample below:
If you opened it in Form View select Close from the File menu to close the Form. Now the remaining task is to insert this form into our Main Control Form and change a few properties of the control to finish the final design and you are ready to go.
Close all other objects and ensure that the Database window is not minimized, if so restore it. Now, open the Control Form in Design View. Select Tile Vertically from the Windows Menu. The Database Window and the Form will arrange side by side. Click on the Forms Tab (if it is not visible), click, drag, and drop the DataFiles2 form on the Control Screen where you want the Menu Options to appear. Resize the control to the desired size. Change its child label Caption to Data Files. Size the child label to the same size as the control and its Special Effect Property to Etched. Save the Form. The completed design on the Control Screen will look like the sample given below:
Click an Item in the Listbox, and the Hyperlinks open the Object (Form, Table, Macro, etc.) attached to it.
When more links are added to the DataFiles2 Table they will appear in the list as well.
Click Next for Control Screen Design...
Download Demo Hyperlinks2k.zip