Relative Folder on Image Path (1 Viewer)

WelshJohn

New member
Local time
Yesterday, 18:13
Joined
Jan 16, 2013
Messages
9
Hi!

I am trying to link an images (.png) onto a form. I have a folder of all the images I want but I want the path to be relative. So that if I move the access file and the images folder to a new location, it will still work.

In the properties for the image, It works fine as C:\Users\john\Desktop\image1.png but what I am looking for is the ability to use "\\images\image1.png" as the file will always be in that relative folder to the db.

Does anyone know the correct syntax for this? putting image1.png in the same directory and just using image1.png works, but this won't be very tidy with 100+ images.

I have tried:

\\images\image1.png
images\image1.png
\images\image1.png

With PictureType set as linked.

I know from searching it is possible through VBA by getting the root directory of the folder and appending the filename. Don't really want to go this root. I also don't particularly want to create a table to store the images or links.

Thanks
 

James Dudden

Access VBA Developer
Local time
Today, 02:13
Joined
Aug 11, 2008
Messages
369
If the images folder is in the same folder as the database then you can use something like this:

Application.CurrentProject.Path & "\Images\"
 

WelshJohn

New member
Local time
Yesterday, 18:13
Joined
Jan 16, 2013
Messages
9
Thanks for your reply!

I'm still getting an error - Microsoft Office Access can't open the file 'Application.CurrentProject.Path & "\Images\image1.png"'

I typed directly into the picture field: 'Application.CurrentProject.Path & "\Images\image1.png"

The folder is entitled Images, is in the right location and the filename and filetype of the file are also both correct.

Anybody know the syntax I can use to get this right? Im using Office 2003. Thanks
 

James Dudden

Access VBA Developer
Local time
Today, 02:13
Joined
Aug 11, 2008
Messages
369
Sorry, didn't explain that very well but the code in the previous post is VBA and would probably be used on the OnCurrent event. Something like this:

Code:
Private Sub Form_Current()
    Dim Path As String
    Path = Application.CurrentProject.Path & "\Images\"
    Me![Image1].Picture = Path & "image1.png"
End Sub


NB: Image1 is the name of the image control and should be renamed as required.
 

WelshJohn

New member
Local time
Yesterday, 18:13
Joined
Jan 16, 2013
Messages
9
Code:
Private Sub Form_Current()
    Dim Path As String
    Path = Application.CurrentProject.Path & "\Images\"
    Me![Image1].Picture = Path & "image1.png"
End Sub

Thanks for the reply. To do this the picture would have to already exist, which would mean me creating an image in form design. The problem with me doing this is that every time I am adding another image the size of my project increases dramatically. It seems that it is storing the images within Access.

Any idea why this is happening or how I can stop it?
 

Simon_MT

Registered User.
Local time
Today, 02:13
Joined
Feb 26, 2007
Messages
2,177
I think this is because prior to Access 2007 it did not handle native formats and it maybe rendering images as a bitmaps. Yawn!

Simon
 

WelshJohn

New member
Local time
Yesterday, 18:13
Joined
Jan 16, 2013
Messages
9
Ah ok. I'm using Access 2003. There must be a way for me to include images without them inflating the size of my database. Can anyone guide me to a solution? Still looking for a way to do this.
 

Simon_MT

Registered User.
Local time
Today, 02:13
Joined
Feb 26, 2007
Messages
2,177
I know this is not the answer you were expecting but try looking at program like dbpix. I waited until access 2007 until I upgraded simply because of the enhanced image capabilities.

Simon
 
Last edited:

GinaWhipp

AWF VIP
Local time
Yesterday, 21:13
Joined
Jun 21, 2011
Messages
5,899
The way I handled this without using a third party tool was...

1. Create a table, mine was tblCompanyProfile.
2. In the table add a field *cpImagePath*
3. Then use something like...

Code:
[FONT=Courier New][COLOR=black][COLOR=black][FONT=Courier New]Dim MyImagePath As String[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]MyImagePath = DLookup("[cpImagePath]", "tblCompanyProfile")[/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=black][FONT=Courier New]Me![Image1].Picture = MyImagePath & "image1.png"[/FONT][/COLOR][/FONT][/COLOR] 
[/COLOR][/FONT]
Now, if it were me I would storing the Image Name in a field.
 

Users who are viewing this thread

Top Bottom