Paths

G

Guest

I have a form in my database which imports paths of photographs that are
converted temporarily in OLE objects. I import the paths using the Open file
dialog box in Microsoft Office Object Library 11. The problem is that my
paths are in an absolute form (e.g. "C:\Data\Pics\photo.jpg") and I want to
convert them in a relative form (when the database file is in the \Data
folder the path should look like this:"\Pics\photo.jpg") in order to make my
database links working in other computers too. If what I'm asking for is too
much, I could use some help editing string in order to use of a default
picture folder in my database folder. For example:
\Data
\Pics
bd1.mdb

This means I'm looking for a way to erase the "C:\Data\" of the path string
in order to make it look like this "\Pics\photo.jpg".

Thanks in advance
 
D

Douglas J. Steele

I'm not really sure how you intend to use relative paths, as Access doesn't
support them, but to remove the C:\Data\ from the front of the string, you
can use the Mid function: Mid(MyPath, 9)
 
S

Stefan Hoffmann

hi Andreas,
If what I'm asking for is too
much, I could use some help editing string in order to use of a default
picture folder in my database folder. For example:
\Data
\Pics
bd1.mdb

This means I'm looking for a way to erase the "C:\Data\" of the path string
in order to make it look like this "\Pics\photo.jpg".
Use CurrentDb.Name to extract the path of your .mdb. And then use
Replace() to mask the absolute path, e.g.

Dim Count As Long
Dim BasePath As String

BasePath = CurrentDb.Name
For Count = Len(Path) To 1 Step - 1
If Mid(BasePath , Count, 1) = "/" Then
Path = Left(BasePath , Count)
Exit For
End If
Next Count
FilePath = Replace(FilePath, BasePath, "")



mfG
--> stefan <--
 
G

Guest

Here is code that will remove the "C:\Data\" as you requested:

Dim strPath As String

strPath = "C:\Data\Pics\photo.jpg"
strPath = Right(strPath, Len(strPath) - 8)

However, you might consider having a table in your database that would hold
information specific to your application, like the path to the pictures.
This could be different for each user of the applicaiton. Then you can
provide your user with a way to define this path. You would then simply read
this path at startup, assigning it to a public variable which you then can
use each time you need to.

Just a thought.
 
G

Graham R Seach

Andreas,

CurrentProject.Path & "\Pics\"

If the database is located in "C:\Data", then the above will return
"C:\Data\Pics\".

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 

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