Change Absolute to Relative path

Crazy Dutch

New member
Local time
Today, 08:56
Joined
Oct 12, 2013
Messages
3
Hi there,

I volunteered to help build a database for the Dutch Rugby Union, which did go quite well up till now. But now they want an image with the contact details. In order to keep the database light, I thought it would be better to link them, so in the contact table there now is a link to the file. In my local computer the path of that link is:
C:\SDCard\SkyDrive\Documenten\NRB\Photos\SamplePhoto.jpg
while the database is stored in:
C:\SDCard\SkyDrive\Documenten\NRB\

What I did manage to do was to create an On Current event in the form properties:
Code:
Private Sub Form_Current()
    PersonPhoto.Picture = Photo
End Sub
Since the Photo field includes the full path, it works perfectly on any computer with the same path. But eventually it will be stored on both their server and during events on local laptops.
I really, really tried to sort this out myself. I already learned Access for this project, but am in over my head with this one. It would be great if the 'Photo' field would only contain 'SamplePhoto.jpg' and sort out the path by determining the path of the Access database + 'Photos'.
Since I believe this is VB code, I posted it here. Any chance someone is able to help a beginner out?

Thanks!
William
 
It takes two steps. The quick simple explanation: One define the location of your database, which can be done by:
Code:
strDirectoryPath = CurrentProject.Path
Second, all the picture files may be located in the same directory as the database (or another directory or sub-directory), but at that point the pointer for each picture is relative to the location of the database and is "hard-coded" in a text field of the database. So the picture location is depicted as:
Code:
strPictureLocation=strDirectoryPath & "\" & "textfield"
That way, if your database is moved from one computer to another, the pictures can still be located.

-----------------------------------------------------------------

See the code below for more detail. Gets into verifying if the image exists.
Code:
If IsBlank(strImageStoragePath & Me.ImageLocation01) Then
            Rem  TRUE condition image location not specified, need to find
            Me.CoverImage.Visible = False
            Me.Label10.Caption = "Image Not available"
         Else
            Rem FALSE condition image locations specified
            strImageStoragePath = DLookup("LocalDefaultImagePath", "tblLocalDefaultTable", "LocalDefaultIDnum = 1")
            If FileExists(strImageStoragePath & "\" & Me.ImageLocation) Then
                    Me.CoverImage.Visible = True
                    Me.CoverImage.Picture = strImageStoragePath & "\" & Me.ImageLocation
                Else
                    Me.CoverImage.Visible = False
                    Me.Label10.Caption = "Image Not available"
                End If
        End If
 
Last edited:
Thank you Paul, that may be a good start, but I still can't completely figure it out.
I am aware that my line of thinking is likely oversimplified, but looking at the function, I would say I only need the Current.Path and the value in Photo. And obviously combine that. So my best try would be

Code:
Private Sub Form_Current()
    PersonPhoto.Picture = Combine(Current.Path, Photo)
End Sub
Looks nice and clean and.... gives an error.
If I need to retrieve the path from a function, do I store that function in same VB file, but just above the Private Sub Form Current?

I do appologize for these questions, but I am a bit lost here.

Thanks!!!
 
Looks like Steve gave you the fish. Did it not work?
 
Sorry to be late with the reply Steve. I read your post after replying to Paul.
After a bit of time I did figure out how it worked. Being a beginner at these things is no fun, but thanks to your kind help it is now solved.
Much appreciate it!
 

Users who are viewing this thread

Back
Top Bottom