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
Try: -
Private Sub Command255_Click()
-
FollowHyperlink DLookup("[Gamma Scan Link]", "[Gamma Scans]", "[Column Name] = '" & Me.Column_Name & "'")
-
End Sub
-
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!!!
Rabbit 12,516
Recognized Expert Moderator MVP
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
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.
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.
Rabbit 12,516
Recognized Expert Moderator MVP
Here's some sample code to get you started. -
Dim rst As Recordset
-
-
Set rst = CurrentDb.OpenRecordset("SELECT Links FROM Table1;")
-
-
Do Until rst.EOF ' EOF is the end of the Recordset
-
FollowHyperlink rst!Links
-
Loop
-
Here's some sample code to get you started. -
Dim rst As Recordset
-
-
Set rst = CurrentDb.OpenRecordset("SELECT Links FROM Table1;")
-
-
Do Until rst.EOF ' EOF is the end of the Recordset
-
FollowHyperlink rst!Links
-
Loop
-
I tried applying it to my code, but I created an infinite loop: - Dim rst As Recordset
-
Dim x As Boolean
-
Dim y As Integer
-
-
Set rst = CurrentDb.OpenRecordset("SELECT [Gamma Scan Link] FROM [Gamma Scans]")
-
-
x = DLookup("[Does Record Exist?]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'") ' Checks if [Does Record Exist?] field has a check mark.
-
If (x = 0) Then ' If checkbox in unchecked, then show message below.
-
y = MsgBox("Sorry, no scan found.", vbInformation, "Sorry")
-
Else ' If checkbox is checked, then follow the link(s) to open the file.
-
Do Until rst.EOF ' EOF is the end of the Recordset
-
FollowHyperlink (DLookup("[Gamma Scan Link]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'"))
-
Loop
-
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?
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. -
Dim rst As Recordset
-
-
Set rst = CurrentDb.OpenRecordset("SELECT Links FROM Table1 WHERE KeyField = " & Me.KeyField & ";")
-
-
Do Until rst.EOF ' EOF is the end of the Recordset
-
FollowHyperlink rst!Links
-
rst.MoveNext
-
Loop
-
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. -
Dim rst As Recordset
-
-
Set rst = CurrentDb.OpenRecordset("SELECT Links FROM Table1 WHERE KeyField = " & Me.KeyField & ";")
-
-
Do Until rst.EOF ' EOF is the end of the Recordset
-
FollowHyperlink rst!Links
-
rst.MoveNext
-
Loop
-
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.
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: -
Set rst = CurrentDb.OpenRecordset("SELECT [Gamma Scan Link] FROM [Gamma Scans] WHERE [Column Name] = '" & Me.[Column Name] & "'")
-
And sorry, yes, it's RecordCount.
If there are links then RecordCount would be larger than 0. Basically -
If rst.RecordCount > 0 Then
-
...
-
Else
-
...
-
End If
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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.
| |
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...
|
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...
|
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...
|
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()
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |