relative path for images

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to distribute an access image DB an CD, so I cannot use abolute paths like X:\image or \\server\image to the image, because these paths are different for every user. If I use relative Paths \image from the DB file to the images, then the images are not displayed. How can I use relative paths?
 
Here are three different implementations of a function that returns the full path to an 'Images' subdirectory
of the directory containing the mdb file.

The last version works in all Access versions from 97, the others may be restricted to more recent versions.


Watch for line-wrap !

Private Function GetImageFolder() As String
GetImageFolder = Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name))) & "Images\"
End Function


Private Function GetImageFolder() As String
Dim DBFullPath As String
DBFullPath = CurrentDb().Name
GetImageFolder = Left(DBFullPath, InStrRev(DBFullPath, "\", Len(DBFullPath))) & "Images\"
End Function


Private Function GetImageFolder() As String
Dim DBFullPath As String
Dim I As Integer

DBFullPath = CurrentDb().Name

' Strip the filename from the full path
For I = 1 To Len(DBFullPath)
If Mid(DBFullPath, I, 1) = "\" Then
GetImageFolder = Left(DBFullPath, I) & "Images\"
End If
Next
End Function

--
_______________________________________________________
http://www.ammara.com/
Image Handling Components, Samples, Solutions and Info
DBPix 2.0 - lossless jpeg rotation, EXIF, asynchronous


=?Utf-8?B?Vy4gTGluZG5lcg==?= said:
I would like to distribute an access image DB an CD, so I cannot use abolute paths like X:\image or \\server\image
to the image, because these paths are different for every user. If I use relative Paths \image from the
DB file to the images, then the images are not displayed. How can I use relative paths?
 
I would have though something with the current directory indicator "." would
work, like "./image.jpg" or ".\image.jpg"? it does for me, in access 2003.

--
Nick H
W. Lindner said:
I would like to distribute an access image DB an CD, so I cannot use
abolute paths like X:\image or \\server\image to the image, because these
paths are different for every user. If I use relative Paths \image from the
DB file to the images, then the images are not displayed. How can I use
relative paths?
 
I think that the 'current' directory is not guaranteed to be (or remain) the same as that of the database
file, in which case this approach would fail (and that is what was happening to the OP). Extracting the
path from CurrentDb().Name should be more reliable.
 
You could also use Application.CurrentProject.Path as the current path for
the database. Then you can refer to directories using something like:

txtFileToUse = Application.CurrentProject.Path & "\" & txtRelativePath & "\"
& txtFileName

Kelvin

Exponent said:
I think that the 'current' directory is not guaranteed to be (or remain)
the same as that of the database
file, in which case this approach would fail (and that is what was
happening to the OP). Extracting the
 
Back
Top