473,778 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command button that locates a hyperlink in a table and then opens it

72 New Member
Hey Everybody, I have an URGENT REQUEST (I need a reply within 24 hours, or I lose my job) I need help writing vba code for a command button. I want this button to locate a hyperlink in a table (the hyperlinks have their own field) based on the record's name (the first field in the table). If the there is a hyperlink for the record, then I want it to be opened. If there is no hyperlink for the record, then I want a message box that states so.

My code so far is as follows:

Private Sub Command255_Clic k()
Dim x As Integer

If ([hyperlink exists]) Then
' Open hyperlink
Else
x = MsgBox("Sorry, link does not exist.", vbInformation, "No link found")
End If

End Sub

Obviously, my problems are that I cannot find a way to specify whether a link exists in the table, and I cannot find a way to locate the link and open it for the user.

I've created another field in the table that has a check box to indicate whether a link exists for each record or not. I don't know if that was needed or not.

Can anyone help me?
May 31 '07
22 5262
mforema
72 New Member
Try:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command255_Click()
  2. FollowHyperlink DLookup("[Gamma Scan Link]", "[Gamma Scans]", "[Column Name] = '" & Me.Column_Name & "'")
  3. End Sub
  4.  
If you have spaces in your names you have to surround it using [ ]
You are awesome! It works great!

Here is the final code with the If...Else statement, if you're interested:

Private Sub Command255_Clic k()
Dim x As Boolean
Dim y As Integer

x = DLookup("[Does Record Exist?]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'") ' Scan either exists or it doesn't.
If (x = 0) Then ' if scan does not exist...
y = MsgBox("Sorry, no scan found.", vbInformation, "Sorry")
Else ' scan does exist; open linked file
FollowHyperlink (DLookup("[Gamma Scan Link]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'"))
End If

End Sub

THANK YOU SO MUCH FOR YOUR HELP AND PATIENCE!!!
May 31 '07 #11
Rabbit
12,516 Recognized Expert Moderator MVP
Glad to help. Good Luck.
Jun 1 '07 #12
mforema
72 New Member
Glad to help. Good Luck.
The HyperlinkTable sometimes has multiple links for the same "Column Name." The code that you gave me only opens the first link pertaining to the "Column Name." How do I ask for all of the pertinant links to be opened? A copy of my code is found below:

Private Sub Command255_Clic k()
Dim x As Boolean
Dim y As Integer

x = DLookup("[Does Record Exist?]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'") ' Check if a link exists in the Gamma Scans table.
If (x = 0) Then ' If link does not exist, then show message below.
y = MsgBox("Sorry, no scan found.", vbInformation, "Sorry")
Else ' If link does exist, then follow the link to open the file.
FollowHyperlink (DLookup("[Gamma Scan Link]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'"))
End If

End Sub
Jun 1 '07 #13
Rabbit
12,516 Recognized Expert Moderator MVP
The HyperlinkTable sometimes has multiple links for the same "Column Name." The code that you gave me only opens the first link pertaining to the "Column Name." How do I ask for all of the pertinant links to be opened? A copy of my code is found below:

Private Sub Command255_Clic k()
Dim x As Boolean
Dim y As Integer

x = DLookup("[Does Record Exist?]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'") ' Check if a link exists in the Gamma Scans table.
If (x = 0) Then ' If link does not exist, then show message below.
y = MsgBox("Sorry, no scan found.", vbInformation, "Sorry")
Else ' If link does exist, then follow the link to open the file.
FollowHyperlink (DLookup("[Gamma Scan Link]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'"))
End If

End Sub
I assume that each hyperlink would have it's own record. Rather than a DLookup, you'll need to create a recordset to return all the records and then use a loop to go through each record and open the link.
Jun 1 '07 #14
mforema
72 New Member
I assume that each hyperlink would have it's own record. Rather than a DLookup, you'll need to create a recordset to return all the records and then use a loop to go through each record and open the link.
How would that look if it were applied to my code? I don't know how to create a recordset or write the loop.
Jun 1 '07 #15
Rabbit
12,516 Recognized Expert Moderator MVP
Here's some sample code to get you started.
Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2.  
  3. Set rst = CurrentDb.OpenRecordset("SELECT Links FROM Table1;")
  4.  
  5. Do Until rst.EOF ' EOF is the end of the Recordset
  6.    FollowHyperlink rst!Links
  7. Loop
  8.  
Jun 1 '07 #16
mforema
72 New Member
Here's some sample code to get you started.
Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2.  
  3. Set rst = CurrentDb.OpenRecordset("SELECT Links FROM Table1;")
  4.  
  5. Do Until rst.EOF ' EOF is the end of the Recordset
  6.    FollowHyperlink rst!Links
  7. Loop
  8.  

I tried applying it to my code, but I created an infinite loop:

Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2. Dim x As Boolean
  3. Dim y As Integer
  4.  
  5. Set rst = CurrentDb.OpenRecordset("SELECT [Gamma Scan Link] FROM [Gamma Scans]")
  6.  
  7. x = DLookup("[Does Record Exist?]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'") ' Checks if [Does Record Exist?] field has a check mark.
  8. If (x = 0) Then     ' If checkbox in unchecked, then show message below.
  9.     y = MsgBox("Sorry, no scan found.", vbInformation, "Sorry")
  10. Else                ' If checkbox is checked, then follow the link(s) to open the file.
  11.     Do Until rst.EOF ' EOF is the end of the Recordset
  12.         FollowHyperlink (DLookup("[Gamma Scan Link]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'"))
  13.     Loop
  14. End If
The Do Loop continues to open the hyperlink. How do I cause the Do Loop to only select and open the hyperlinks once?
Jun 4 '07 #17
Rabbit
12,516 Recognized Expert Moderator MVP
Have the recordset only select the links where the foreign key matches the primary key.

Then you can just use rst.RecordsetCo unt to determine if there are any links. Using a recordset means you no longer need to use DLookup.

And my apologies, my code was flawed in the first place.

Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2.  
  3. Set rst = CurrentDb.OpenRecordset("SELECT Links FROM Table1 WHERE KeyField = " & Me.KeyField & ";")
  4.  
  5. Do Until rst.EOF ' EOF is the end of the Recordset
  6.    FollowHyperlink rst!Links
  7.    rst.MoveNext
  8. Loop
  9.  
Jun 4 '07 #18
mforema
72 New Member
Have the recordset only select the links where the foreign key matches the primary key.

Then you can just use rst.RecordsetCo unt to determine if there are any links. Using a recordset means you no longer need to use DLookup.

And my apologies, my code was flawed in the first place.

Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2.  
  3. Set rst = CurrentDb.OpenRecordset("SELECT Links FROM Table1 WHERE KeyField = " & Me.KeyField & ";")
  4.  
  5. Do Until rst.EOF ' EOF is the end of the Recordset
  6.    FollowHyperlink rst!Links
  7.    rst.MoveNext
  8. Loop
  9.  
I tried your code, but a run-time error occured. It said, "Too few parameters. Expected 1." When I clicked the Debug button, this line of code was highlighted:

Set rst = CurrentDb.OpenR ecordset("SELEC T [Gamma Scan Link] FROM [Gamma Scans] WHERE [Column Name] = " & Me.[Column Name] & ";")

Did I do something wrong, or leave something out?

Also, is it RecordsetCount or RecordCount , because I can't find any help info on the former? How would I use it in my if...else statement? Or, in other words, how do I use it to tell whether there are anyother links? I'm sorry for being so confused, but I have very little experience in VBA, let alone programming.
Jun 4 '07 #19
Rabbit
12,516 Recognized Expert Moderator MVP
I tried your code, but a run-time error occured. It said, "Too few parameters. Expected 1." When I clicked the Debug button, this line of code was highlighted:

Set rst = CurrentDb.OpenR ecordset("SELEC T [Gamma Scan Link] FROM [Gamma Scans] WHERE [Column Name] = " & Me.[Column Name] & ";")

Did I do something wrong, or leave something out?

Also, is it RecordsetCount or RecordCount , because I can't find any help info on the former? How would I use it in my if...else statement? Or, in other words, how do I use it to tell whether there are anyother links? I'm sorry for being so confused, but I have very little experience in VBA, let alone programming.
Try:
Expand|Select|Wrap|Line Numbers
  1. Set rst = CurrentDb.OpenRecordset("SELECT [Gamma Scan Link] FROM [Gamma Scans] WHERE [Column Name] = '" & Me.[Column Name] & "'")
  2.  
And sorry, yes, it's RecordCount.

If there are links then RecordCount would be larger than 0. Basically
Expand|Select|Wrap|Line Numbers
  1. If rst.RecordCount > 0 Then
  2.    ...
  3. Else
  4.    ...
  5. End If
  6.  
Jun 4 '07 #20

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

Similar topics

2
2293
by: deko | last post by:
Is there a special syntax for hyperlinks in queries? I have a table of hyperlinked documents displayed in a subform datasheet. Clicking the hyperlink opens the document from the hard drive. I have an Autonumber field (Doc_ID) in the table that indexes the documents, but sometimes the same hyperlink can have different Doc_ID's, so I need a query to find the hyperlink in the table. For example: SELECT Entity_ID FROM tblDocuments WHERE...
5
2350
by: Maria João | last post by:
I have a table with one field that ia a hyperlink to a pdf file that opens a specific file. Since these files are very big, I would need to change the hyperlink path, so that I could send the hyperlink to one CDROM. I can do this part, but my problem ist that this DataBase is distributed in several machines in several places (not connected) and in each machine the CDROM drive have it's own letter (D: or E: ...). But I still have...
6
1385
by: Mark R | last post by:
Hi Guru's, I have a frontend application where my boss wants to when people are using the database. I have a form which OnOpen, inserts the username, network login and date/time it was opened to a table. I have created a 'Close' button which when clicked, updates the 'Logged_out' time and then quits the application. My problem is that when users click on the cross (top right corner) to close the database, this time is not logged. Is...
2
1783
by: Big E | last post by:
I'm using ASP.Net and SQL Server. I have a table called states. I have 2 forms. On form 1 is the 50 states in textboxes created with a loop. I want to have those 50 or 45 or whatever amount of states have a hyperlink. Once you click the hyperlink it will take the stateId from the click event and use the Get method to send it to the next page. Page 2 will simply use the browswer get method to show information based on that stateid. So my...
2
5217
by: emc_cos | last post by:
I have a very nice parent child relationship happening between a main form and 8 subforms. The main form is the data entry point for a table that holds textual data like names, notes and the like. It also holds the primary key which is an alpha-numeric file designation. The subforms are the data entry point for another table that holds numeric values for time spent on tasks.
8
4799
by: jmarcrum | last post by:
Hello all, i have a continuous form that displays about 1000 records and opens when I click a button. When the form opens, the user has the option of checking a checkbox that is located beside each record. The checkbox is labeled "Move" (for moving multiple records at a time to another year). Of course, the checkbox is set as a control "moveRecord" on a table that the query is pulling from. So if the user checks one record, then clicks to...
16
2734
by: Steve | last post by:
I am working on a database that has a main menu, many sub-menus and some sub-sub-menus. They are all forms that have numerous command buttons on them to open forms and reports in the database. The database has hundreds of forms and reports. I was asked to go through all the menu forms and determine if all the buttons worked, if there were any problems when either the form or report opened and to come up with a list of the forms and reports...
14
22189
by: alnino | last post by:
Hi, I have a command button on a form that the user can use to browse to a file and the user can select that file and a hyperlink to that file is stored in a txtfield for that record. I then have a command button that a user can click to open and view the associated file. This all works fine. BUT: I would like the command button that allows the user to view the file to be hidden if no hyperlink was added. In other words the txtfield...
1
6263
by: alnino | last post by:
Hi, On a form I have a command button that allows a user to browse for a file (PDF, Word, etc…). This command button then stores a hyperlink to the file within an associated txtfield in the table. The VB to browse for the file is as follows Private Sub CmdBuildingAdd_Click() Me!txtSelectedFile = BrowseFiles()
0
10298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10127
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8957
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7475
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.