Hyperlink not hyperlinking

J

JustinP

I am using a file picker dialog to get the file path and record it in a
hyperlink field. This works, however the hyperlink does not hyperlink.
When I click on the hyperlink in the table it does nothing but when I
go to the end of the hyperlink and press delete a few times it does
work (as if there are empty spaces that are preventing it from working.
I've tried using trim but it doesn't work. Any suggestions? (code
included below)

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object
Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

If IsNull(Me![Link1]) Then
Me![Link1] = Trim(vrtSelectedItem)
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = Trim(vrtSelectedItem)
End If

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing

End Sub
 
D

Douglas J. Steele

I never use the FileDialog object, preferring to use the GetOpenFileName API
(as illustrated in http://www.mvps.org/access/api/api0001.htm at "The Access
Web"), so I'm not positive, but with the API, the file names that are
returned have a Null character (Chr$(0) or vbNullChar) at the end of them.

Try:

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object

Dim intNullChar As Integer
Dim strFile As String
Dim vrtSelectedItem As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems


intNullChar = InStr(vrtSelectedItem, vbNullChar)
If intNullChar > 0 Then
strFile = Trim(Left(vrtSelectedItem, intNullChar - 1))
Else
strFile = Trim(vrtSelectedItem)
End If

If IsNull(Me![Link1]) Then
Me![Link1] = strFile
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = strFile
End If
Next vrtSelectedItem
End If
End With

Set fd = Nothing

End Sub
 
J

JustinP

Still doesn't seem to work. Why do the file names have a null char
returned? Thanks for your help.
I never use the FileDialog object, preferring to use the GetOpenFileName API
(as illustrated in http://www.mvps.org/access/api/api0001.htm at "The Access
Web"), so I'm not positive, but with the API, the file names that are
returned have a Null character (Chr$(0) or vbNullChar) at the end of them.

Try:

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object

Dim intNullChar As Integer
Dim strFile As String
Dim vrtSelectedItem As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems


intNullChar = InStr(vrtSelectedItem, vbNullChar)
If intNullChar > 0 Then
strFile = Trim(Left(vrtSelectedItem, intNullChar - 1))
Else
strFile = Trim(vrtSelectedItem)
End If

If IsNull(Me![Link1]) Then
Me![Link1] = strFile
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = strFile
End If
Next vrtSelectedItem
End If
End With

Set fd = Nothing

End Sub

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


JustinP said:
I am using a file picker dialog to get the file path and record it in a
hyperlink field. This works, however the hyperlink does not hyperlink.
When I click on the hyperlink in the table it does nothing but when I
go to the end of the hyperlink and press delete a few times it does
work (as if there are empty spaces that are preventing it from working.
I've tried using trim but it doesn't work. Any suggestions? (code
included below)

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object
Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

If IsNull(Me![Link1]) Then
Me![Link1] = Trim(vrtSelectedItem)
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = Trim(vrtSelectedItem)
End If

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing

End Sub
 
D

Douglas J. Steele

APIs are written in C or C++. That's how C and C++ treats strings.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


JustinP said:
Still doesn't seem to work. Why do the file names have a null char
returned? Thanks for your help.
I never use the FileDialog object, preferring to use the GetOpenFileName
API
(as illustrated in http://www.mvps.org/access/api/api0001.htm at "The
Access
Web"), so I'm not positive, but with the API, the file names that are
returned have a Null character (Chr$(0) or vbNullChar) at the end of
them.

Try:

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object

Dim intNullChar As Integer
Dim strFile As String
Dim vrtSelectedItem As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems


intNullChar = InStr(vrtSelectedItem, vbNullChar)
If intNullChar > 0 Then
strFile = Trim(Left(vrtSelectedItem, intNullChar - 1))
Else
strFile = Trim(vrtSelectedItem)
End If

If IsNull(Me![Link1]) Then
Me![Link1] = strFile
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = strFile
End If
Next vrtSelectedItem
End If
End With

Set fd = Nothing

End Sub

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


JustinP said:
I am using a file picker dialog to get the file path and record it in a
hyperlink field. This works, however the hyperlink does not hyperlink.
When I click on the hyperlink in the table it does nothing but when I
go to the end of the hyperlink and press delete a few times it does
work (as if there are empty spaces that are preventing it from working.
I've tried using trim but it doesn't work. Any suggestions? (code
included below)

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object
Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

If IsNull(Me![Link1]) Then
Me![Link1] = Trim(vrtSelectedItem)
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = Trim(vrtSelectedItem)
End If

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing

End Sub
 
D

Dirk Goldgar

JustinP said:
I am using a file picker dialog to get the file path and record it in
a hyperlink field. This works, however the hyperlink does not
hyperlink. When I click on the hyperlink in the table it does nothing
but when I go to the end of the hyperlink and press delete a few
times it does work (as if there are empty spaces that are preventing
it from working. I've tried using trim but it doesn't work. Any
suggestions? (code included below)

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object
Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

If IsNull(Me![Link1]) Then
Me![Link1] = Trim(vrtSelectedItem)
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = Trim(vrtSelectedItem)
End If

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing

End Sub

Try

Me![Link1] = "#" & Trim(vrtSelectedItem) & "#"
 
J

JustinP

That works! Thanks...

Dirk said:
JustinP said:
I am using a file picker dialog to get the file path and record it in
a hyperlink field. This works, however the hyperlink does not
hyperlink. When I click on the hyperlink in the table it does nothing
but when I go to the end of the hyperlink and press delete a few
times it does work (as if there are empty spaces that are preventing
it from working. I've tried using trim but it doesn't work. Any
suggestions? (code included below)

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object
Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

If IsNull(Me![Link1]) Then
Me![Link1] = Trim(vrtSelectedItem)
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = Trim(vrtSelectedItem)
End If

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing

End Sub

Try

Me![Link1] = "#" & Trim(vrtSelectedItem) & "#"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
R

Roger Carlson

Perhaps a tad late, but on my website (www.rogersaccesslibrary.com), is a
small Access database sample called "SetHyperlink.mdb" which illustrates
both Doug's use of the API and Dick's suggestion of putting # signs around
the returned strings.

Dangit, you guys. Why don't you leave some for *me*? <grin>

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Douglas J. Steele said:
I never use the FileDialog object, preferring to use the GetOpenFileName API
(as illustrated in http://www.mvps.org/access/api/api0001.htm at "The Access
Web"), so I'm not positive, but with the API, the file names that are
returned have a Null character (Chr$(0) or vbNullChar) at the end of them.

Try:

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object

Dim intNullChar As Integer
Dim strFile As String
Dim vrtSelectedItem As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems


intNullChar = InStr(vrtSelectedItem, vbNullChar)
If intNullChar > 0 Then
strFile = Trim(Left(vrtSelectedItem, intNullChar - 1))
Else
strFile = Trim(vrtSelectedItem)
End If

If IsNull(Me![Link1]) Then
Me![Link1] = strFile
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = strFile
End If
Next vrtSelectedItem
End If
End With

Set fd = Nothing

End Sub

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


JustinP said:
I am using a file picker dialog to get the file path and record it in a
hyperlink field. This works, however the hyperlink does not hyperlink.
When I click on the hyperlink in the table it does nothing but when I
go to the end of the hyperlink and press delete a few times it does
work (as if there are empty spaces that are preventing it from working.
I've tried using trim but it doesn't work. Any suggestions? (code
included below)

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object
Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

If IsNull(Me![Link1]) Then
Me![Link1] = Trim(vrtSelectedItem)
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = Trim(vrtSelectedItem)
End If

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing

End Sub
 
R

Roger Carlson

Er -- um -- I had my news reader sorted wrong and thought this was a current
post. *blush* Carry on.

--
--Roger Carlson
MS Access MVP



Roger Carlson said:
Perhaps a tad late, but on my website (www.rogersaccesslibrary.com), is a
small Access database sample called "SetHyperlink.mdb" which illustrates
both Doug's use of the API and Dick's suggestion of putting # signs around
the returned strings.

Dangit, you guys. Why don't you leave some for *me*? <grin>

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Douglas J. Steele said:
I never use the FileDialog object, preferring to use the GetOpenFileName API
(as illustrated in http://www.mvps.org/access/api/api0001.htm at "The Access
Web"), so I'm not positive, but with the API, the file names that are
returned have a Null character (Chr$(0) or vbNullChar) at the end of them.

Try:

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object

Dim intNullChar As Integer
Dim strFile As String
Dim vrtSelectedItem As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems


intNullChar = InStr(vrtSelectedItem, vbNullChar)
If intNullChar > 0 Then
strFile = Trim(Left(vrtSelectedItem, intNullChar - 1))
Else
strFile = Trim(vrtSelectedItem)
End If

If IsNull(Me![Link1]) Then
Me![Link1] = strFile
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = strFile
End If
Next vrtSelectedItem
End If
End With

Set fd = Nothing

End Sub

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


JustinP said:
I am using a file picker dialog to get the file path and record it in a
hyperlink field. This works, however the hyperlink does not hyperlink.
When I click on the hyperlink in the table it does nothing but when I
go to the end of the hyperlink and press delete a few times it does
work (as if there are empty spaces that are preventing it from working.
I've tried using trim but it doesn't work. Any suggestions? (code
included below)

Sub Main()

Dim fd As FileDialog 'Declare a variable as a FileDialog object
Set fd = Application.FileDialog(msoFileDialogFilePicker)

Dim vrtSelectedItem As Variant

With fd

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

If IsNull(Me![Link1]) Then
Me![Link1] = Trim(vrtSelectedItem)
ElseIf Not IsNull(Me![Link1]) And IsNull(Me![Link2]) Then
Me![Link2] = Trim(vrtSelectedItem)
End If

Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top