views:

24

answers:

1

I have an Image object. I have the Picture type set to linked, so I can change the picture if I want. I have the Picture property set to the picture name.

I would think that access would use relitive addressing and simple looking in the current directory for the image. But it does not and I get an error telling me it cannot find the picture.

Anyone have a solution? (Other than setting the Picture type to embedded or using the full file address?)

Thanks!

Update:

Tried this:

Private Sub Form_Load()
Dim file As String
file = CurrentDb().Name
file = Replace(file, ".mdb", ".bmp")
Me.Image46.Picture = file

End Sub

It works, except I still get the error message. I click O.K. and it works. Just need the error message to go away.

SOLUTION: Use the above code (or the code posted in the answer below) and then set the 'picture type' to "embedded" and then delete the 'picture' field so that it says "(none)". Save and run. It should work.

THANKS!

+1  A: 

You could set the property on the forms OnLoad event like this

Me.imgMy_image.picture=getDBPath & “mypicture.bmp”

Here is the getDBPath function

Public Function GetDBPath() As String
    Dim strFullPath As String
    Dim I As Integer

    strFullPath = CurrentDb().Name

    For I = Len(strFullPath) To 1 Step -1
        If Mid(strFullPath, I, 1) = "\" Then
            GetDBPath = Left(strFullPath, I)
            Exit For
        End If
    Next
End Function

Before anyone comments yes I know in access 2000 and above you can use currentproject.path but I’m stuck in the land that time forgot so need that custom function, it still works with later versions of access

Kevin Ross
kralco626
Just a reference to the fact that at work I’m stuck using access97 which does not have the CurrentProject.path function so I have to use the custom one. I mean come on it’s a programme that is nearly old enough to drink! (In the UK)
Kevin Ross
lol ya they need to update. even my company uses 2003. Anyways. I'm updating above. I tried something and still have an error.
kralco626
solution is: set the picture type to embedded, and then delete the file name.
kralco626
I have lots of databases that began life before A2000, so I've got my own custom code for getting the path from the database name. It could all easily be replaced with CurrentProject.Path, but what's the point of bothering? I do have some newer code that uses CurrentProject.Path, of course.
David-W-Fenton