Picture on a form: Using a relative path

  • Thread starter Thread starter Name
  • Start date Start date
N

Name

Hi,

I have an access database for some paintings. On a form I want to show both
the image and the details of the painting.

The database xx.mdb is in I:\Whatewer\mdb and the images are in
I:\Whatever\images.

I can accomplish this if I use full path of the images in ImageDir field.
However, when I try to use relative path in the ImageDir field I have no
luck.

I tried the images, \images, .\images notations.

The database is in Access 2000 format, but I use it with Access 2002.

Thanks for any help,
 
Access doesn't work with relative paths: it will only allow full paths.
Having said that, though, it shouldn't be that difficult to change your
paths if you find that they aren't correct, just as you have to change paths
for linked tables.

A problem is that the Current Directory when you start Access usually isn't
the same directory as your MDB is in.
 
In testing, I found that Access will accept the relative path in code or you
can type in the relative path. However, once it's been placed in the
control, it gets converted to the full path. The control won't save it as a
relative path.

Me.Image0.Picture = ".\Picture.jpg"
or in your case
Me.Image0.Picture = "..\Images\Picture.jpg"

In your example you only used one dot, which would mean to look in the same
directory. You need to use two dots to go up one directory then down to the
images directory.
 
The 'current' directory is not necessarily the same each time the application runs, and it can be changed
during the lifetime of the application.

How about using something like this:

Me.Image0.Picture = Application.CurrentProject.Path & "\images\" & "Picture.jpg"
 
Thanks,

Exponent you are right, I also thought about it after my initial post. Maybe
you can help me with a modified solution:

Some more detail:

The field for the path is "DISK_YERI" and there is also another field named
"IMAGE" where the name of the picture is stored:

DISK_YERI holds the value: "I:\rsmmdb\xx\image0x.jpg" and the IMAGE holds
the value "image0x.jpg.

The code for the form is:

---------------
Private Sub Form_Current()
On Error Resume Next
Me![ImagePic].Picture = Me![DISK_YERI]
Me!ImagePic.Visible = Len("" & Me![DISK_YERI]) > 0
End Sub

Private Sub Form_AfterUpdate()
On Error Resume Next
Me![ImagePic].Picture = Me![DISK_YERI]
End Sub
-------------------

Now I want to be able to get rid of the field DISK_YERI and use the field
IMAGE in the form. I tried to modify the line to match my table but it did
not work.

Can you modify the code above so that it will work.

Thanks,
 
Assuming that the database is in the folder:
I:\rsmmdb\

and *all* the images are in:
I:\rsmmdb\xx\

try using the following line in Form_Current():
Me![ImagePic].Picture = Application.CurrentProject.Path & "\xx\" & Me![IMAGE]

Watch for line wrap.

You could also check that the filename has a valid length, and that the file exists (using the dir command).


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



Name said:
Thanks,

Exponent you are right, I also thought about it after my initial post. Maybe
you can help me with a modified solution:

Some more detail:

The field for the path is "DISK_YERI" and there is also another field named
"IMAGE" where the name of the picture is stored:

DISK_YERI holds the value: "I:\rsmmdb\xx\image0x.jpg" and the IMAGE holds
the value "image0x.jpg.

The code for the form is:

---------------
Private Sub Form_Current()
On Error Resume Next
Me![ImagePic].Picture = Me![DISK_YERI]
Me!ImagePic.Visible = Len("" & Me![DISK_YERI]) > 0
End Sub

Private Sub Form_AfterUpdate()
On Error Resume Next
Me![ImagePic].Picture = Me![DISK_YERI]
End Sub
-------------------

Now I want to be able to get rid of the field DISK_YERI and use the field
IMAGE in the form. I tried to modify the line to match my table but it did
not work.

Can you modify the code above so that it will work.

Thanks,


Exponent said:
The 'current' directory is not necessarily the same each time the
application runs, and it can be changed
during the lifetime of the application.

How about using something like this:

Me.Image0.Picture = Application.CurrentProject.Path & "\images\" &
"Picture.jpg"

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

Exponent said:
Assuming that the database is in the folder:
I:\rsmmdb\

and *all* the images are in:
I:\rsmmdb\xx\

try using the following line in Form_Current():
Me![ImagePic].Picture = Application.CurrentProject.Path & "\xx\" &
Me![IMAGE]

Watch for line wrap.

You could also check that the filename has a valid length, and that the
file exists (using the dir command).


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



Name said:
Thanks,

Exponent you are right, I also thought about it after my initial post.
Maybe
you can help me with a modified solution:

Some more detail:

The field for the path is "DISK_YERI" and there is also another field
named
"IMAGE" where the name of the picture is stored:

DISK_YERI holds the value: "I:\rsmmdb\xx\image0x.jpg" and the IMAGE holds
the value "image0x.jpg.

The code for the form is:

---------------
Private Sub Form_Current()
On Error Resume Next
Me![ImagePic].Picture = Me![DISK_YERI]
Me!ImagePic.Visible = Len("" & Me![DISK_YERI]) > 0
End Sub

Private Sub Form_AfterUpdate()
On Error Resume Next
Me![ImagePic].Picture = Me![DISK_YERI]
End Sub
-------------------

Now I want to be able to get rid of the field DISK_YERI and use the field
IMAGE in the form. I tried to modify the line to match my table but it did
not work.

Can you modify the code above so that it will work.

Thanks,


Exponent said:
The 'current' directory is not necessarily the same each time the
application runs, and it can be changed
during the lifetime of the application.

How about using something like this:

Me.Image0.Picture = Application.CurrentProject.Path & "\images\" &
"Picture.jpg"

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


Hi,

I have an access database for some paintings. On a form I want to show
both
the image and the details of the painting.

The database xx.mdb is in I:\Whatewer\mdb and the images are in
I:\Whatever\images.

I can accomplish this if I use full path of the images in ImageDir
field.
However, when I try to use relative path in the ImageDir field I have no
luck.

I tried the images, \images, .\images notations.

The database is in Access 2000 format, but I use it with Access 2002.

Thanks for any help,
 
Back
Top