473,387 Members | 1,757 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,387 software developers and data experts.

How to save a Caption for a Hyperlink, different from the Hyperlink itself?

446 Expert 256MB
I'm trying to create a form where a user enters a document reference number and then clicks a command button to add a hyperlink to the document, via a file picker.

Thanks to Adezii's excellent article http://bytes.com/topic/access/answer...ink-into-table I can manage to create a hyperlink to the document and store it in the table, but it is the full hyperlink path not the reference number of the document that is displayed.

I have a workaround at present, where I have overlaid a second textbox [HCaption] over the one holding the hyperlink [Hlink]. If I type my document reference into [HCaption] box, then click the command button I can programatically add the 'caption' to the selected item to create the hyperlink, by modifying Adezii's code as below.

Expand|Select|Wrap|Line Numbers
  1. If .Show Then
  2.     For Each varItem In .SelectedItems 'There will only be 1
  3.  
  4.         'Replaced the original code marked with *, with this
  5.         'to produce different Caption and Address
  6.         Me!Hlink = Me!HCaption & "#" & varItem
  7.  
  8.       ''*Caption and Address of Hyperlink will be the same (Caption#Address)
  9.       '*strHyperlinkFile = varItem & "#" & varItem
  10.       '*Me!Hlink = strHyperlinkFile
  11.  
  12.     Next varItem
  13.   End If
I then have to make [HCaption] Visible = False so that the user so that the user can click on the hyperlink box if it is populated. This works but I feel is messy; I have overlaid boxes and I have to keep two fields on the table.

I should add, I spent some time using just the [Hlink] text box and trying to enter the caption directly into that but Access seems to append 'http:\' or whatever, depending where the target is, and it does not work.

On the up-side, not all documents are scanned and available via a hyperlink and this is clear because they show as black text rather than blue underlined text. But I would welcome any comments on how to improve this.

The massive advantage of a hyperlink is that the document can be in any format that the default browser can interpret, so you don't have to read the file extension to know what program to shell out to.
Nov 5 '09 #1
10 2972
ChipR
1,287 Expert 1GB
I find this interesting, since I haven't used hyperlinks yet. I'm going to test some things today or tomorrow and get back to you.
Nov 5 '09 #2
ADezii
8,834 Expert 8TB
@sierra7
Hello sierra7, I had no problem implementing this logic. Is the Control Source for [HLink] a Hyperlink Data Type?
Nov 5 '09 #3
ChipR
1,287 Expert 1GB
Here's how I've got this working. With an unbound textbox (txtLink) set
Display As Hyperlink = If Hyperlink

I have a button for:
Expand|Select|Wrap|Line Numbers
  1.     Dim fDialog As Object
  2.     Dim varFile As Variant
  3.     Dim strFileName As String
  4.  
  5.     Set fDialog = Application.FileDialog(3) 'msoFileDialogFilePicker)
  6.  
  7.     With fDialog
  8.         .AllowMultiSelect = False
  9.         .Title = "Please select the input file"
  10.         .Filters.Clear
  11.         If .Show = True Then
  12.             For Each varFile In .SelectedItems
  13.                 strFileName = varFile
  14.             Next
  15.         Else
  16.             Exit Sub
  17.         End If
  18.     End With
  19.  
  20.     Set fDialog = Nothing
  21.     Set varFile = Nothing
  22.  
  23.     HLink = txtLink & "#" & strFileName
  24.     Me.Dirty = False
  25.     txtLink.IsHyperlink = True
  26.     txtLink = HLink
Now, if you want the caption to show properly when you move to a record:
Expand|Select|Wrap|Line Numbers
  1. 'Didn't test this
  2. Private Sub Form_Current()
  3.     If HLink > "" Then
  4.         txtLink.IsHyperlink = True
  5.         txtLink = Left(HLink, InStr(HLink, "#") - 1)
  6.     Else
  7.         txtLink.IsHyperlink = False
  8.         txtLink = ""
  9.     End If
  10. End Sub
Nov 5 '09 #4
sierra7
446 Expert 256MB
@ADezii
Yes, [HLink] is a hyperlink data type and I added [HCaption] as Text when I could not get the result I wanted.

With hindsight I am warming to this solution because, as I said in my original post, it is clear which records have a hyperlinked document (a scanned certificate) and which don't. This is useful. I don't want to use two fields both displaying the same data.

Also with hindsight it was silly typing into a hypertext field and expecting to get text out. After leaving the field then tabbing back and pressing F2 to edit (and Shift+F2) you can see what Access has added. I tried InStr() for '#' on [HLink].Value, then substringing but it was a mess.

I need to read what ChipR is saying
Nov 5 '09 #5
ChipR
1,287 Expert 1GB
Sorry, that Form_Current code isn't right. All you really have to do is:
Expand|Select|Wrap|Line Numbers
  1. ...
  2.     If HLink > "" Then 
  3.         txtLink.IsHyperlink = True 
  4.         txtLink = HLink
  5. ...
I was trying to illustrate how you could get just the caption, and I put it in the wrong place.
Nov 5 '09 #6
sierra7
446 Expert 256MB
Hi ChipR, thanks for your time
Yes I'm new to using hyperlinks in Access too and finding it a little trickier that I imagined.

You chose to enter the 'caption' via an unbound text box which work well if there is always a file to link to. However, my 'caption' is a Certificate Number and sometimes there is not a document to link to until it is scanned. To persist this value until a file is available I must store it in the table. I thought I could store it in the hypertext field, but then it appears blue and is underlined, hence the additional field.

I have tried your idea of setting the 'IsHyperLink' property of a textbox but have not had results I expected. i.e. if the underlying field is hyperlink data type the text is still underlined and blue when IsHyperlink is False and will still link (!?). If the underlying field is Text holding a valid hyperlink text string, then the display can be toggles to show just the caption part by making IsHyperlink True; aTool-tip also appears but will never link.

It looks as though I must rely on my OnCurrent event to toggle the Visible property of the two text boxes if [HLink] holds a string (containing a #)

Thanks again for your time
Nov 6 '09 #7
ADezii
8,834 Expert 8TB
@sierra7
Hello sierra7, I think I have a crude, workable solution to your unique circumstance, but only you can decide for sure:
  1. Create 2 Fields in your Primary Table, or use existing ones.
    1. [Link] {HYPERLINK} - will contain the actual Hyperlink itself.
    2. [NoLink] {TEXT} - will display Caption only if Address Component does not exist.
  2. Create 2 Text Boxes Bound to this Fields and make them Invisible (New Record).
  3. Examine your concatenated Value and determine if it is a Hyperlink or not. If it is, write to the Hyperlink Field, if not write to the Text Field.
    Expand|Select|Wrap|Line Numbers
    1. Dim strHyperlink As String
    2.  
    3. strHyperlink = Me!HCaption & "#" & varItem
    4.  
    5. If HyperlinkPart(strHyperlink, acAddress) <> "" Then      'It is a Hyperlink
    6.   Me![Link] = strHyperlink
    7. Else
    8.   Me![NoLink] = strHyperlink
    9. End If
  4. The code is crude and incomplete, but it is only the concept that I wanted to bring across.
  5. Similar functionality can be used in the Form's Current() Event in order to display/overlay the proper Control.
Nov 6 '09 #8
NeoPa
32,556 Expert Mod 16PB
I recently started playing in this area myself. You may find Error 7980: HyperlinkAddress or HyperlinkSubAddress read-only for Hyperlink helpful.
Nov 8 '09 #9
sierra7
446 Expert 256MB
Hi Guys
Thanks for all your suggestions.

ADezii, I shall check out the HyperlinkPart() function to see if I can make use of it as it is new to me. I did not have much luck using 'IsHyperlink'.

NeoPa, I had read the Allen Brown article to get to my solution, although I find that the hyperlink works ok without the trailing hash '#'. It was intesting to see he uses a double hash '##' to refer to a table or form within ACCESS. I liked your code to handle Nulls.
Nov 9 '09 #10
NeoPa
32,556 Expert Mod 16PB
@sierra7
Thanks :)

The full explanation can be found in Using "&" and "+" in WHERE Clause.
Nov 9 '09 #11

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

Similar topics

27
by: aa | last post by:
Thought this question might be out of this NG's scope, there are always knowledgable people who might hava an answer. A hyperlink to a shortcut to a file returnes an empty screen, and the source...
2
by: aqualizard | last post by:
I have made and image with a caption using CSS, but I am hoping someone can show me how to do it better. By better I mean less HTML, and hopefully have it work with any sized image where I do not...
9
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored...
4
by: John | last post by:
Hi, I generate a report in a comma delimited file and give it a name like MyReport.csv . I then set a Hyperlink control to point tp the file HyperLink1.text = "Download"...
1
by: Adam Knight | last post by:
Thanks to all who responded to my previous post. Can anyone tell me is their a way to add a hyperlink in a datagrid caption? Cheers, Adam
5
by: scrawford | last post by:
Hi all, I want to save a variable's value in a form permenantly, is there a way I can do that? Background is: I have created a database that imports one of two different files when the user...
15
by: Jimmy Stewart | last post by:
I want to use a calculated function for the caption on my tab controls. I used the following code: Me.Page28.Caption = "Expenses & "]" This should display the following: " Expenses " where...
1
by: Shannon Richards | last post by:
Hello All: I have implemented a custom configuration section in my app.config file as follows: <configSections> <section name="AdminUIConfig" type="TestMgr.UIConfigSection,TestMgr"/>...
20
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.