<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener("load", function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=34083602&amp;blogName=LEARN+MS-ACCESS+TIPS+AND+TRICKS&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F&amp;blogLocale=en_US&amp;homepageUrl=http%3A%2F%2Fwww.msaccesstips.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" allowtransparency="true" title="Blogger Navigation and Search"></iframe> <div></div>
www.msaccesstips.com

LEARN MS-ACCESS TIPS AND TRICKS


International Response Fund

LEARN MS-ACCESS TIPS AND TRICKS

↑ Grab this Headline Animator

Your Ad Here
Friday, May 25, 2007

Open Forms with Hyperlinks in Listbox

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. As a result, based on the value in the Type field of the control table, a Form 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 same, but we will do it differently. It is better to know more than one method, which we can use in our various Projects, rather than using the same thing everywhere.

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 few records into 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 segments format, separated by # symbol.




Display Text # External File’s Hyperlink Address # Internal Objects Hyperlink SubAddress # Control Tip Text

You can use the last segment to display a text when you point on the Hyperlink and that segment we will ignore 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.

1. Type a Descriptive Text in the Text to Display box on the top of the dialog control.

2. 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 a space between the type and the Name in the Address: box at the bottom.

Example-1:

    1. Text to Display: Edit Employees’ Data
    2. Address: #Form Employees

Click 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 hash (#) 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 a 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 to Edit a Hyperlink field is a tricky business. When you point 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.


  1. Point on the field and move the arrow 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.
  2. 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 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 data view. Close the Form and save it with the Name: DataFiles2. Open the form in design view to change its properties to look like a listbox.


Unfinished Form image (click)









  1. Click View menu and remove the check mark from the Form Header/Footer item. This action will display a warning message, click Yes to remove the Header & Footer Sections of the Form.

  1. 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 Alt+Enter keys or Click Properties from the View Menu to display the Form’s property sheet. Change the following Form Properties:

    1. Allow Datasheet View : No
    2. Allow Additions : No
    3. Allow Deletions: No
    4. Data Entry: No
    5. Scroll Bars: Neither
    6. Record Selectors: No
    7. Navigation Buttons: No
    8. Dividing Lines: No
    9. Border Style: None
    10. ControlBox: No
    11. Min Max Buttons: None
    12. Close Button: No

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

  1. Select the Seq Field control and change its width property to 0.2”
  2. Select Seq & Desc text boxes together, select Align -- > Left from the Format Menu, which will bring the controls close together.
  3. Select Shortest from the Format -- > Size Option to change both controls height to the same value.
  4. Now change the Properties (still both controls selected) of the controls to the following values:

    1. Special Effect: Flat
    2. Top: 0
    3. Back Color: 128
    4. Fore Color: 16777215

Resize the form’s detail section close to the field sizes using the sizing handles at right and bottom edges of the form. Change both control’s border Color & Font weight:

    1. Border Color: 128
    2. Font Weight: Bold

  1. Select the Seq field alone and change the following properties to:

a. Enabled: No

b. Locked: Yes

The completed form in design view will look like the sample given below:

Form Design Completed (click)








When opened in Form View, it will look like the sample below:


ListBox Preview (Click)





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 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 of 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:


Listbox on Control Screen View (click)

Click an Item in the Listbox, the Hyperlinks opens 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...

Labels:

8 Comments:

Blogger ahmedtharwat19 said…

many thanks to you
but can you up to us an examole to see that

or send it to me at : ahmedtharwat19@yahoo.com

November 17, 2009 12:35 PM  
Blogger a.p.r. pillai said…

Yes, I will forward a sample database to you shortly.

regards,
a.p.r. pillai

November 17, 2009 10:21 PM  
Anonymous Anonymous said…

Do you know how to connect a hyperlink to a command button that sends you to the hyperlink based on selections picked from combo boxes? Example to clarify:

You want to set up a car database so you make tables with certain information regarding the car, but for the purpose of this, lets just look at the model table. The model table (tblModel) consists of the following fields: ModelID, ModelName, MakeID, Hyperlink. The MakeID would be a link if you had cascading combo boxes in the form. So from a form the user would select a Make (cboMake), which would then break down the Models (cboModel). Based on the selection made by the user for the model the code in the command button would compare the model selected in cboModel to the model in tblModel and return the hyperlink (field 4) so that when the user clicked the command button he would see a pdf for that model.

Thanks in advance
Cory Hall - cory_r_hall@yahoo.com

November 18, 2009 8:16 PM  
Blogger a.p.r. pillai said…

Yes, this is possible. Sample Code is given below:

Private Sub cboModel_Click()
Dim myhype, xy As String, xcboModel
Dim db As Database, rst As Recordset

xcboModel = Me![cboModel]

Set db = CurrentDb
Set rst = db.OpenRecordset("tblModel", dbOpenDynaset)

rst.FindFirst "ModelID = " & Chr$(34) & xcboModel & Chr$(34)

If Not rst.NoMatch Then
Set myhype = rst![Hlink]
xy = HyperlinkPart(myhype, acAddress)
Me.cmdPDF.HyperlinkAddress = xy
End If

rst.Close
End Sub

The above Code Runs when you Click on the cboModel ComboBox. Searches the Table for the Model Value selected in the Combo Box and when found retrieves the HyperLink Value into myhype Variable. The HyperLinkPart() Function extracts the .pdf file pathname from the Hyperlink Field. The extracted Path is inserted into the HyperLink Address Property of the cmdPDF Command Button. When you Click the Command Button the PDF File will be opened.

The Hyperlink Field Value in the tblModel must be set in the following format:

Display Text#pdf File PathName##Tooltip Text

Example:

Model Document#C:\My Documents\Lexus.pdf##Click

You may visit the following link to learn how to refresh a ComboBox contents that depends on another ComboBox value selection:

http://www.msaccesstips.com/2008/03/refresh-dependant-combo-box-contents.shtml


Regards,
a.p.r. pillai

November 19, 2009 12:09 AM  
Blogger Cory said…

The code works great, thanks a lot. Was just going to ask about two lines:

Set rst = db.OpenRecordset("tblModel", dbOpenDynaset)
rst.FindFirst "ModelID = " & Chr$(34) & xcboModel & Chr$(34)

I know if you have spaces in your titles such as Model ID instead of ModelID, you usually put the name in brackets such as [Model ID], but it seems for both tblModel and ModelID above it gives debug errors when you bracket them.

November 19, 2009 5:26 PM  
Blogger a.p.r. pillai said…

You don't need to put [] in the first statement, even if there is space in the Tahle Name.

But, if there is space in the ModelID Field Name then you must insert the square brackets. When you do see that you are not adding extra spaces immediately after or before the brackets.

Regards,

November 19, 2009 5:45 PM  
Blogger Cory said…

With the following code, I'm trying to get a bit fancier and embed the pdf within the form. I'm using a microsoft web browser object to do this, but when i click the cmdPDF button it just shows a page that can't find the hyperlink. acxWebBrowser is the name of the web browser object.

Private Sub cboModel_Click()
Dim myhype, xy As String, xcboModel
Dim db As Database, rst As Recordset

xcboModel = Me![cboModel]

Set db = CurrentDb
Set rst = db.OpenRecordset("tblModel", dbOpenDynaset)

rst.FindFirst "ModelID = " & Chr$(34) & xcboModel & Chr$(34)

If Not rst.NoMatch Then
Set myhype = rst![Hlink]
xy = HyperlinkPart(myhype, acAddress)
Me.acxWebBrowser.Navigate "xy"
End If

rst.Close
End Sub

December 07, 2009 8:53 PM  
Blogger a.p.r. pillai said…

Remove the Quotes from Me.acxWebBrowser.Navigate "xy"

Me.acxWebBrowser.Navigate xy

and try again.

December 07, 2009 9:03 PM  

Post a Comment

Note:Comments subject to Review by Blog Author before displaying.

Links to this post:

Create a Link

<< Home


Creative Commons License
Learn MS-Access Tips and Tricks by msaccesstips.com is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 India License.



This Page is best viewed with 1280 x 1024 Resolution

   FEATURED LINKS
SITEMAP
Command Button Animation
3D Headings on Forms
MsgBox & Office Assistant
Reminder Ticker
MS-Access & E-Mails
Automated E-Mail Alerts
MsgBox with Options Menu
Colorful Command Buttons
Configure Lotus Notes
Alerts through Network
Running this site has become a costly affair as the revenue from Ads is not sufficient to support it. If you find these pages informative & useful and would like to extend a helping hand, then please do it here.





Link Back to us with this Button

Learn MS-Access

Copy and Paste this HTML Code in your Webpage


Add to Technorati Favorites

Programming Blogs - Blog Catalog Blog Directory
Powered by FeedBurner
Add to Google

Software
Computers blogs
TopOfBlogs




AddMe - Search Engine Optimization Submit Your Site Free!
Go BlogZ Ave Blogs
eBlogzilla Changing LINKS
LS Blogs Blogarama
blog search directory BlogUniverse
Find Blogs in Directory RSS Directory
blogskinny.com ShowcaseBlogs.com
Amfibi

Search Engine Optimization and SEO Tools
Dmegs Web Directory Takeaway for Sale Businesses For Sale
Free Submission Directory Free site submission

Free Listing
 





Free Page Rank Checker

AddThis Social Bookmark Button

Enter your email address:

Delivered by FeedBurner



Top Blogs


Microsoft Access is the Jewell among MS-Office suite of Applications. Its Security features are excellent and works fine in Network environment. MS-Access can link/upload data from any Data Source. Applications that you design should be user-friendly and visually pleasing too. Here I would like to share my experience in Microsoft Access Programming with you and I am sure that you will find them interesting too.

My Photo
Name: Ramachandran Pillai
Location: Cochin, India

I am not an Access Guru and not through MS-Access yet. More to learn and I don’t think that aspect has any end because others have their own style of using this tool. We can learn lot more tricks, other than what we already know, from others too. My programming skills in COBOL, BASIC, Turbo-C, dBase, FoxPro, Visual Basic & Basic HTML attained through self-learning. I wrote my first COBOL Program in 1975 for ICL1901, 3rd Generation Main Frame Computer. Worked as a Computer Operator (NCR VRX8555 Mainframe Machine upto 1990) with M/s. Y.B.A. Kanoo, Saudi Arabia. Started using MS-Access Ver.2 in 1996, when dBase III+ and Foxbase (later version Foxpro) were my favorite DBMS. During Last 13 Year period I have developed more than 45 In-House Applications (medium & small) under MS-Access for our Organization, a leading Automotive Company in Oman. All the Applications are fully Secured and runs under Windows Network. It is my pleasure to share my experience with others. Anything interesting that you would like to share with me, please do. My E-mail Address: aprpillai@msaccesstips.com


If you need a Demo of any of the Topic explained here, send me an E-mail to: aprpillai@msaccesstips.com
with the Topic Description, I shall try to send a sample database to you.


Access Tips | Email | Reports | Report Tricks | Graphs | Forms | Menus | Animation | Security | Internet | How TOs | Linking | Query | Progress Meter | Alerts | Process Tips | Access Functions |




Site Designed by:www.msaccesstips.com