473,779 Members | 1,905 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 5263
mforema
72 New Member
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.  
Thanks! The change worked. I was able to get my code to work, but without the RecordCount. Initially, I tried using the if...else format the you gave me, but I ran into a problem with NULL values. Some of the records do not have links available; therefore, I left those spaces blank. The blank spaces resulted in a NULL value. So, when I tried to run the code, the RecordCount was greater than 0 for ALL of the "Columns." I'm not sure how I could get around that problem and still use the RecordCount. So, I just used my old code with some modifications, and it worked!

My code is found below:

Expand|Select|Wrap|Line Numbers
  1. Dim x As Boolean
  2. Dim y As Integer
  3. Dim rst As Recordset
  4.  
  5. x = DLookup("[Does Record Exist?]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'")
  6. If (x = 0) Then ' if record does not have a checked box, then show message below.
  7.     y = MsgBox("No scans for column " & [Column Name] & ".", vbInformation, "Sorry")
  8. Else ' if record does have a checked box, then
  9.     ' Create a recordset that only includes the gamma scan links for the current column.
  10.     Set rst = CurrentDb.OpenRecordset("SELECT [Gamma Scan Link] FROM [Gamma Scans] WHERE [Column Name] = '" & Me.[Column Name] & "'")
  11.     Do Until rst.EOF ' EOF is the end of the Recordset
  12.         FollowHyperlink rst![Gamma Scan Link] ' follow the link(s).
  13.         rst.MoveNext
  14.     Loop
  15. End If
So, thanks again for your time and patience! You've been a great help! Do you see anything wrong with it?
Jun 4 '07 #21
Rabbit
12,516 Recognized Expert Moderator MVP
Thanks! The change worked. I was able to get my code to work, but without the RecordCount. Initially, I tried using the if...else format the you gave me, but I ran into a problem with NULL values. Some of the records do not have links available; therefore, I left those spaces blank. The blank spaces resulted in a NULL value. So, when I tried to run the code, the RecordCount was greater than 0 for ALL of the "Columns." I'm not sure how I could get around that problem and still use the RecordCount. So, I just used my old code with some modifications, and it worked!

My code is found below:

Expand|Select|Wrap|Line Numbers
  1. Dim x As Boolean
  2. Dim y As Integer
  3. Dim rst As Recordset
  4.  
  5. x = DLookup("[Does Record Exist?]", "Gamma Scans", "[Column Name] = '" & Me.[Column Name] & "'")
  6. If (x = 0) Then ' if record does not have a checked box, then show message below.
  7.     y = MsgBox("No scans for column " & [Column Name] & ".", vbInformation, "Sorry")
  8. Else ' if record does have a checked box, then
  9.     ' Create a recordset that only includes the gamma scan links for the current column.
  10.     Set rst = CurrentDb.OpenRecordset("SELECT [Gamma Scan Link] FROM [Gamma Scans] WHERE [Column Name] = '" & Me.[Column Name] & "'")
  11.     Do Until rst.EOF ' EOF is the end of the Recordset
  12.         FollowHyperlink rst![Gamma Scan Link] ' follow the link(s).
  13.         rst.MoveNext
  14.     Loop
  15. End If
So, thanks again for your time and patience! You've been a great help! Do you see anything wrong with it?
Not a problem, good luck.

There's nothing wrong with the coding other than it can be cleaned up a bit. I took out the comments but leave those in.

Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2.  
  3. Set rst = CurrentDb.OpenRecordset("SELECT [Gamma Scan Link] FROM [Gamma Scans] WHERE [Column Name] = '" & Me.[Column Name] & "' And [Gamma Scan Link] Is Not Null")
  4.  
  5. If (rst.RecordCount = 0) Then
  6.     MsgBox "No scans for column " & [Column Name] & ".", vbInformation, "Sorry"
  7. Else
  8.     Do Until rst.EOF
  9.         FollowHyperlink rst![Gamma Scan Link]
  10.         rst.MoveNext
  11.     Loop
  12. End If
Jun 4 '07 #22
mforema
72 New Member
Not a problem, good luck.

There's nothing wrong with the coding other than it can be cleaned up a bit. I took out the comments but leave those in.

Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2.  
  3. Set rst = CurrentDb.OpenRecordset("SELECT [Gamma Scan Link] FROM [Gamma Scans] WHERE [Column Name] = '" & Me.[Column Name] & "' And [Gamma Scan Link] Is Not Null")
  4.  
  5. If (rst.RecordCount = 0) Then
  6.     MsgBox "No scans for column " & [Column Name] & ".", vbInformation, "Sorry"
  7. Else
  8.     Do Until rst.EOF
  9.         FollowHyperlink rst![Gamma Scan Link]
  10.         rst.MoveNext
  11.     Loop
  12. End If
Ah, yes! That is a much nicer code! It allows me to delete the [Does Record Exist?] field, which had the checkboxes.

Thanks!
Jun 4 '07 #23

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

Similar topics

2
2294
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
2351
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
1784
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
4800
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
22190
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
9471
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
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
10136
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
10071
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
9925
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
8958
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
7478
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
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.