Using text field to display images on a form or report

J

John F

I was going to use attachments to do this instead of a text field but after
rummaging around here I have nod decided to use a text field.

Access knows where it started up from. Can this information be used in a way
that the image file can be accessed relative to where access started up in
order to be able to move the folder or copy the database to another computer
without breaking the qualified path and having to recreate all of the path
names to display the images? If this is possible then how is it implemented?

Thanks in advance
 
B

BruceM via AccessMonster.com

CurrentProject.Path will give you the path to the folder in which the
application (the current database) resides.

You should also be able to use the UNC path (\\ServerName\ShareName\
FolderName) to the desired folder. It sounds as if everybody is using a
single database file on a network location, and you want everybody to be able
to use the mapped drive letters they used to get there. Sharing a single
database file by multiple users is apt to lead to corruption, which can be
especially vexing if the data (tables) are in the same file as the forms,
reports, and queries.

Best practice is to split the application between front end (user interface)
and back end (data files), and give each user their own copy of the front end.
In that case you will need to use either the UNC path, or have something like
a local settings table where each user can store mapped drive letters and
such. UNC path is simpler to implement. More here on splitting:

http://allenbrowne.com/ser-01.html
 
J

John F

It is a single user database that I use at home on my desktop computer and
when I travel I transfer the database to my laptop. Unfortunatly the fully
qualified file name is different for each respective computer. All I wanted
to be able to do is not have to recreate links to the images that is the
reason I'm looking to make the path relative to the folder that contains the
database and subfoldes contain the image files.

I am not familar with the use of CurrentProject.Path, how would this be used
with an unbound box that displayes the image in the form? I have the boxes
displaying the images now but as configured the box is displaying the image
base on a fully qualified path stored in a text field.
 
B

BruceM via AccessMonster.com

CurrentProject.Path gives the path to the database. If the images folder (I
will call it Images) is located in the same folder as the database you could
do:

Dim strPath as String

strPath = CurrentProject.Path & "\Images"

I don't know how exactly you are displaying the images, but presumably it
involves a path to the images folder. Use the above instead of the path you
are now using.

There may be more going on here than I understand, as I don't see why you
don't just use the same folder name for both computers. You mention the
desktop and laptop computers, but then there is the phrase "each respective
computer", so are there more than two computers, or what exactly?

John said:
It is a single user database that I use at home on my desktop computer and
when I travel I transfer the database to my laptop. Unfortunatly the fully
qualified file name is different for each respective computer. All I wanted
to be able to do is not have to recreate links to the images that is the
reason I'm looking to make the path relative to the folder that contains the
database and subfoldes contain the image files.

I am not familar with the use of CurrentProject.Path, how would this be used
with an unbound box that displayes the image in the form? I have the boxes
displaying the images now but as configured the box is displaying the image
base on a fully qualified path stored in a text field.
CurrentProject.Path will give you the path to the folder in which the
application (the current database) resides.
[quoted text clipped - 25 lines]
 
J

John F

I am storing the database in "My Documents", on the desktop which has
multiple HDs and is on drive D: and on the laptop which has 1 HD it is on
drive C:, this is the only difference in the path name.

How I am displaying the image is using an “Image Box†with a control source
set to [txtPath] which is the field that stores the path to the image which
looks like D:\users\my name\documents\the database folder\Images\name of
picture.jpg and on the laptop it starts thus C:\users…………….


BruceM via AccessMonster.com said:
CurrentProject.Path gives the path to the database. If the images folder (I
will call it Images) is located in the same folder as the database you could
do:

Dim strPath as String

strPath = CurrentProject.Path & "\Images"

I don't know how exactly you are displaying the images, but presumably it
involves a path to the images folder. Use the above instead of the path you
are now using.

There may be more going on here than I understand, as I don't see why you
don't just use the same folder name for both computers. You mention the
desktop and laptop computers, but then there is the phrase "each respective
computer", so are there more than two computers, or what exactly?

John said:
It is a single user database that I use at home on my desktop computer and
when I travel I transfer the database to my laptop. Unfortunatly the fully
qualified file name is different for each respective computer. All I wanted
to be able to do is not have to recreate links to the images that is the
reason I'm looking to make the path relative to the folder that contains the
database and subfoldes contain the image files.

I am not familar with the use of CurrentProject.Path, how would this be used
with an unbound box that displayes the image in the form? I have the boxes
displaying the images now but as configured the box is displaying the image
base on a fully qualified path stored in a text field.
CurrentProject.Path will give you the path to the folder in which the
application (the current database) resides.
[quoted text clipped - 25 lines]
Thanks in advance
 
B

BruceM via AccessMonster.com

As I said in a previous posting, you can get the path to the database folder
with CurrentProject.Path. It may go something like this in the form's
Current event, assuming an image control named imgMain:

Dim strFile as String, strPath As String

strFile = "MyFile.jpg"
strPath = CurrentProject.Path & "\Images\" & strFile

Debug.Print strPath

Me.imgMain.PictureType = 1 ' Linked
Me.imgMain.Picture = strPath

I don't know where the file name is coming from. It may be that you can use
the InStrRev function together with the Right function to extract the file
name from the end of a string that consists of the full path, whether you use
the Insert Hyperlink dialog to insert the link or generate the file name by
other means that include the path.

I'm not completely certain whether the PictureType line of code is needed.
It does no harm, in any case.

Assuming you are using a command button to add the link, you will need the
same code in its Click event, with the addition of:
Me.Refresh

I can't tell if you are familiar with the use of the Immdiate code window.
When you run code, Debug.Print causes whatever you specify (strPath in this
case) to be written to the immediate code window, which you can view after
running the code (in the case of the Current event, after you have arrived at
a record) by pressing Ctrl + G. You can also go to the immediate window at
any time to test code. To see CurrentProject.Path, in the immediate window:
?CurrentProject.Path

To see the database name:

?CurrentDB.Name

To see the current date and time:

?Now()

And so forth. Note that the question mark is needed. Also, the above are
system-wide functions, so you can find their values in the immediate window.
The current path applies no matter where you are in the database, so you can
test their values at any time. Same for global variables, although it is
usually better to avoid those if you can. Note that you cannot use the
immediate window in this way to find the value of a control or of a variable
that is generated within a procedure, as there is no context. However, if
you place a break point into a procedure you can test values located within
the procedure. For instance, if you place a break point in the code above,
when the code breaks you can type in the immediate window:
?strPath
and you will see the value of strPath. However, if the code is not running,
there is no context for strPath.


John said:
I am storing the database in "My Documents", on the desktop which has
multiple HDs and is on drive D: and on the laptop which has 1 HD it is on
drive C:, this is the only difference in the path name.

How I am displaying the image is using an “Image Box†with a control source
set to [txtPath] which is the field that stores the path to the image which
looks like D:\users\my name\documents\the database folder\Images\name of
picture.jpg and on the laptop it starts thus C:\users…………….
CurrentProject.Path gives the path to the database. If the images folder (I
will call it Images) is located in the same folder as the database you could
[quoted text clipped - 30 lines]
 

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