473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to have a button open a hyperlink?

I have a form with a Combo box and a button.
I want the user to be able to choose an option in the combo box, click the button, and a related .pdf is opened.

The Combo box has a control source in a table. Within the same record as the control source, a 2nd column contains a hyperlink with a file path to a related .pdf.

What I am struggling with is the code associated with the clicking of the button.
How do I command Access/VBA to go to the record chosen, find the related .pdf, and open the .pdf with a click of a button?
Sep 9 '10 #1

✓ answered by TheSmileyCoder

Okay, first its a good idea if you use comboboxes in code (as we are about to) to rename them so they do not have the same name as the field in the table. So we rename the CompanyName Combobox to cmb_CompanyName.

We then add a button, btn_GoTo, and if you look at its properties, select events, and then on Click, you select the 3 ... on the righthand side. Click them and choose Event Procedure.

Then you will be taken to the Visual basic editing window where some code we be written allready:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_GoTo_Click()
  2.  
  3. End Sub
Modify this to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_GoTo_Click()
  2.   dim strPath as string
  3.   'Error check
  4.   If isNull(Me.cmb_CompanyName) Then
  5.     Msgbox "No document selected",vbokonly
  6.     Exit Sub
  7.   End If
  8.  
  9.   'Get path
  10.   strPath=Dlookup("InfoPDF","tbl_Doc","FileID=" & Me.cmb_CompanyName)
  11.   application.FollowHyperlink strPath
  12. End Sub

6 27972
TheSmileyCoder
2,322 Expert Mod 2GB
Hi Chris and welcome to Bytes.
This can easily be done, but it would be alot easier to give a precise and useful answer for you if you could provide:
Name of your combobox, its Controlsource value, and Row Source value.
Name of your document table, and fields like the example provided:
Expand|Select|Wrap|Line Numbers
  1. tbl_Documents
  2.   Key_Document, Autonumber
  3.   tx_DocTitle, Text
  4.   tx_DocFullPath, Text
I can allready say that once you have the correct path, its a simple matter of:
Expand|Select|Wrap|Line Numbers
  1. Application.FollowHyperlink strFullPath
where strFullPath is the full path to your document. If you provide the required information im sure one of us can help with the rest.
Sep 9 '10 #2
On the form
ComboBox: CompanyName
Controlsource value: CompanyName
Row Source value: SELECT CompanyInfo.FileID, CompanyInfo.CompanyName FROM CompanyInfo ORDER BY CompanyInfo.CompanyName;

On the table:
Autonumber: FileID
Text Column: CompanyName
Hyperlink Column: InfoPDF
Sep 9 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Okay, first its a good idea if you use comboboxes in code (as we are about to) to rename them so they do not have the same name as the field in the table. So we rename the CompanyName Combobox to cmb_CompanyName.

We then add a button, btn_GoTo, and if you look at its properties, select events, and then on Click, you select the 3 ... on the righthand side. Click them and choose Event Procedure.

Then you will be taken to the Visual basic editing window where some code we be written allready:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_GoTo_Click()
  2.  
  3. End Sub
Modify this to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_GoTo_Click()
  2.   dim strPath as string
  3.   'Error check
  4.   If isNull(Me.cmb_CompanyName) Then
  5.     Msgbox "No document selected",vbokonly
  6.     Exit Sub
  7.   End If
  8.  
  9.   'Get path
  10.   strPath=Dlookup("InfoPDF","tbl_Doc","FileID=" & Me.cmb_CompanyName)
  11.   application.FollowHyperlink strPath
  12. End Sub
Sep 9 '10 #4
Thank you very much TheSmileyOne.

I am having further issues because not every record in my table has a hyperlink path.

I have been working with a If statement, but i cannot get it to work. I am unsure what I am commanding the if statement to do, but I receive the Msgbox everytime (I changed "tbl_doc" to my table name):

If strPath = DLookup("InfoPDF", "CompanyInfo", "FileID=" & Me.cmb_CompanyName) Then
Application.FollowHyperlink strPath
Else
MsgBox "No supporting document submitted", vbExclamation
End If
Sep 10 '10 #5
TheSmileyCoder
2,322 Expert Mod 2GB
In the code you posted you don't show where you got strPath from. If you want to check whether or not anything is returned you can do:

Expand|Select|Wrap|Line Numbers
  1. strPath = nz(DLookup("InfoPDF", "CompanyInfo", "FileID=" & Me.cmb_CompanyName),"")
  2.  
  3. if strPath & ""<>"" Then
  4. Application.FollowHyperlink strPath
  5. Else
  6. MsgBox "No supporting document submitted", vbExclamation
  7. End If 
When posting code, please post full code, and remember to use the code tags around your code [code]...[/code]
Sep 10 '10 #6
Thank you so much!!
Sep 10 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mariame | last post by:
Hi everyone I have a button that open a new web page so i use the following script response.write("<script>window.open(url,'Name')</script>") every time the user click on the button it opens a new...
3
by: Agnes | last post by:
I got a web page which show different document and let the user to download. One document, one download button. now i want to create a "D/L All" button to download all document by one click....
3
by: kuldeep singh sethi | last post by:
Hi All I want to know about the difference between link button and hyperlink button. How much Both are same and where should be used. Regards Kuldeep singh sethi
3
by: dannyf | last post by:
I have an access database that I need to open scanned jpegs from. I don't care if it opens "in" access or if it just invokes the native application for that file type. I need the button to look at...
6
by: efultz | last post by:
I am trying to figure out how to click on a button and have it open a web page. I am not asking for the logic to handle the click. Moreover I am looking for the logic that I need to run to actually...
4
by: Marine | last post by:
Hi, My project must connect to a Sql Server quite often to read/write datas. I am wondering : do i have to open the connection to the Sql Server at the beginning when the application loads, then...
0
by: Josh | last post by:
How can I set a hyperlink in my data list to open a new window? TIA Josh
8
by: shalakap | last post by:
hi All!!!!!!!!!! i m trying to place command button on reports in access but it doesnt show the onclick event to connect it with macro or procedure. secondly,i tried to place hyperlink on report...
2
by: =?Utf-8?B?Q2hhcnRz?= | last post by:
I have been writing C# programs to spider yellow page to get list of restaurant name, address to the database. When I encounter button or hyperlink, I don’t know how to use the program to click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.