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. - If .Show Then
-
For Each varItem In .SelectedItems 'There will only be 1
-
-
'Replaced the original code marked with *, with this
-
'to produce different Caption and Address
-
Me!Hlink = Me!HCaption & "#" & varItem
-
-
''*Caption and Address of Hyperlink will be the same (Caption#Address)
-
'*strHyperlinkFile = varItem & "#" & varItem
-
'*Me!Hlink = strHyperlinkFile
-
-
Next varItem
-
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.
10 2972
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.
@sierra7
Hello sierra7, I had no problem implementing this logic. Is the Control Source for [HLink] a Hyperlink Data Type?
Here's how I've got this working. With an unbound textbox (txtLink) set
Display As Hyperlink = If Hyperlink
I have a button for: - Dim fDialog As Object
-
Dim varFile As Variant
-
Dim strFileName As String
-
-
Set fDialog = Application.FileDialog(3) 'msoFileDialogFilePicker)
-
-
With fDialog
-
.AllowMultiSelect = False
-
.Title = "Please select the input file"
-
.Filters.Clear
-
If .Show = True Then
-
For Each varFile In .SelectedItems
-
strFileName = varFile
-
Next
-
Else
-
Exit Sub
-
End If
-
End With
-
-
Set fDialog = Nothing
-
Set varFile = Nothing
-
-
HLink = txtLink & "#" & strFileName
-
Me.Dirty = False
-
txtLink.IsHyperlink = True
-
txtLink = HLink
Now, if you want the caption to show properly when you move to a record: - 'Didn't test this
-
Private Sub Form_Current()
-
If HLink > "" Then
-
txtLink.IsHyperlink = True
-
txtLink = Left(HLink, InStr(HLink, "#") - 1)
-
Else
-
txtLink.IsHyperlink = False
-
txtLink = ""
-
End If
-
End Sub
@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
Sorry, that Form_Current code isn't right. All you really have to do is: - ...
-
If HLink > "" Then
-
txtLink.IsHyperlink = True
-
txtLink = HLink
-
...
I was trying to illustrate how you could get just the caption, and I put it in the wrong place.
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
@sierra7
Hello sierra7, I think I have a crude, workable solution to your unique circumstance, but only you can decide for sure: - Create 2 Fields in your Primary Table, or use existing ones.
- [Link] {HYPERLINK} - will contain the actual Hyperlink itself.
- [NoLink] {TEXT} - will display Caption only if Address Component does not exist.
- Create 2 Text Boxes Bound to this Fields and make them Invisible (New Record).
- 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.
- Dim strHyperlink As String
-
-
strHyperlink = Me!HCaption & "#" & varItem
-
-
If HyperlinkPart(strHyperlink, acAddress) <> "" Then 'It is a Hyperlink
-
Me![Link] = strHyperlink
-
Else
-
Me![NoLink] = strHyperlink
-
End If
- The code is crude and incomplete, but it is only the concept that I wanted to bring across.
- Similar functionality can be used in the Form's Current() Event in order to display/overlay the proper Control.
NeoPa 32,556
Expert Mod 16PB
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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"...
|
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
|
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...
|
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...
|
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"/>...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| | |