Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a relative hyperlink

Status
Not open for further replies.

Lightenup

Programmer
Jan 24, 2003
16
US
I have relative hyperlinks (\Photos\picturename.jpg) in a table. Each link opens a specific picture. When you click on the link it automatically looks on the C drive for the 'Photos' folder then the picturename then opens the picture in my default browser. This works great if the 'Photos' folder with the pictures are all loaded on the C: drive. I am also using this link to load a picture into an image control in an Access form. This also works fine with the relative link IF the folder is on the C: drive.

However, I'm putting the database and photos on a CD. I need my relative link to look back at the CD which has a 'Photos' folder with the database and photos in it and bring the picture into the image control on the form.

Appreciate your help.
L
 
My approach is to always have a table(s) with Path informaiton. So, perhaps create a default database table with the path name of where the image files are located. Then formulate the entire file name and path name,... set the source to that calculated field. htwh, Steve Medvid
"IT Consultant & Web Master"
e-Mail: Stephen_Medvid@GMACM.com

Chester County, PA Residents
Please Show Your Support...
 
This last weekend I was working to have Access recurse through a directory & subdirectories and pull off the filenames into a directory. I was just thinking something like that you might be able to create the database of photos on the fly, or just for an initial setup without the hassle of inputting all the photos. Either search on google for "visual basic" and "recurse subdirectory", or ask and I can post the code (it's pretty good size).
 
I have a table with the relative file path of each picture (\Photos\Test1\picture.jpg). If you click on the hyperlink in the table, it is able to follow the path back to the CD and open the picture. I have a text box on the form where the hyperlink is visible. If you click on it, it follows the relative file path back to the CD. In both instances it opens the picture in the system's default viewer.

Unfortunately bringing the picture into the image control only works if the 'Photos' folder and contents are on the C: drive. Here's my code. Can't figure out why the hyperlink works as a relative link and looks back at the CD, but the image control looks for the C: drive.

Dim strPic As String
txtLink.SetFocus
If txtLink.Text <> &quot;&quot; Then
Screen.MousePointer = 11
strPic = txtLink.Text
imgPic.Picture = strPic
Screen.MousePointer = 1
Else
strPic = (&quot;\Photos\NotAvail.gif&quot;)
imgPic.Picture = strPic
Screen.MousePointer = 1
End If
Exit Sub

Still scratching my head. Doesn't seem like it should be that big a deal.
L
 
Looks to me like your code is probably picking up the display text instead of the address of the hyperlink. Hyperlinks look like

displaytext#address#subaddress

in raw format.

That said, your displaytext and address are most likely the same value even though you technically want the address and is not the problem your looking to solve but may become one.

I don't know why the hyperlink when you click on it is managing the relative path to the CD ok. But evidently, the image control is starting on drive C:

You need to determine the drive of cdrom and concatenate that into your string...

strPic = &quot;D:&quot; & txtLink.Text

The above assumes the cd drive is D:

I've seen some examples that reference the CD drive by a system alias... You can try this but I'm going on my best recollection so forgive me if it doesn't work.

strPic = &quot;<CDROM>&quot; & txtLink.Text

 
lameid,

Your strPic = &quot;<CDROM>&quot; & txtLink.text was in the right direction but first I had to get the system to figure out where the CD rom drive was. I found this code at the Microsoft site (changed it slightly).

This went in the form.
Private Sub Main()
' Call the GetFirstCdRomDriveLetter() and store the
' return value in strDriveLetter.
If strDriveLetter <> &quot;&quot; Then Exit Sub

strDriveLetter = GetFirstCdRomDriveLetter()

End Sub

In the sub on the form that uses the drive letter I have:

strPic = txtLink
strPic = strDriveLetter & strPic

In the module.
Declare Function GetDriveType Lib &quot;kernel32&quot; Alias _
&quot;GetDriveTypeA&quot; (ByVal nDrive As String) As Long

Declare Function GetLogicalDriveStrings Lib &quot;kernel32&quot; Alias _
&quot;GetLogicalDriveStringsA&quot; (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Public Const DRIVE_CDROM As Long = 5

' FUNCTION:
' GetFirstCdRomDriveLetter()
'
' PURPOSE:
' Finds the first CD-ROM device and then returns its drive letter.
'
' ARGUMENTS:
' None
'
' RETURNS:
' A string that represents the first CD-ROM drive letter. If the
' function fails for any reason, it returns vbNullString.
'
' **********************************************************************


Function GetFirstCdRomDriveLetter() As String

' Declare variables.
Dim lDriveType As Long
Dim strDrive As String
Dim lStart As Long: lStart = 1

' Create a string to hold the logical drives.
Dim strDrives As String
strDrives = Space(150)

' Get the logial drives on the system.
' If the function fails it returns zero.
Dim lRetVal As Long
lRetVal = GetLogicalDriveStrings(150, strDrives)

' Check to see if GetLogicalDriveStrings() worked.
If lRetVal = 0 Then
' Get GetLogicalDriveStrings() failed.
GetFirstCdRomDriveLetter = vbNullString
Exit Function
End If

' Get the string that represents the first drive.
strDrive = Mid(strDrives, lStart, 3)

Do
' Test the first drive.
lDriveType = GetDriveType(strDrive)
' Check if the drive type is a CD-ROM.
If lDriveType = DRIVE_CDROM Then
' Found the first CD-ROM drive on the system.
GetFirstCdRomDriveLetter = strDrive
Exit Function
End If
' Increment lStart to next drive in the string.
lStart = lStart + 4
' Get the string that represents the first drive.
strDrive = Mid(strDrives, lStart, 3)
Loop While (Mid(strDrives, lStart, 1) <> vbNullChar)

End Function

This works like a charm but I'm still interested if anyone know how to use the 'alias' system name and how to handle it if they have more than one CD rom drive. Right now I'm using an error handler.

Thanks.
L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top