Images in Access

G

Guest

I have a file of jpgs that are listed by student number. They are in the same
folder as the data base I want to use. I need to display the students picture
(400+) and their name and other data. Is there a way these can be displayed
without inserting each one in the table? I think I can build the form but am
not sure how to get the picture and the student infomation to merge.
 
D

Douglas J. Steele

The sample imaging databases at http://accdevel.tripod.com illustrate three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat, and
some other problems, associated with images in OLE Objects.

If you are printing the images in reports, to avoid memory leakage, you
should also see MVP Stephen Lebans' http://www.lebans.com/printfailures.htm.
PrintFailure.zip is an Access97 MDB containing a report that fails during
the Access formatting process prior to being spooled to the Printer Driver.
This MDB also contains code showing how to convert the contents of the Image
control to a Bitmap file prior to printing. This helps alleviate the "Out of
Memory" error that can popup when printing image intensive reports.
 
G

Guest

Doug;

Sorry but you lost me. I did look at the sample but it is way above what I
understand. Access 2000 is what we are trying to use. We have all the student
pictures in one folder. I just do not want to spend several hours inserting
the locations in the table.
 
S

Stephen Lebans

Hi Andrew,
I'm assuming you have a field in your table that contains the Student ID
#'s used to name the Jpegs. I'll also assume that you have a TextBox
control on your form that is bound to this StudentID field and is named
txtStudentID.
Place the standard Image(NOT Bound or Unbound Object Frame) control on
your form, name it ImagePhoto.

In the Form's Current event do something like:
Me.ImagePhoto.Picture = "C:\StudentPhotos\" & Me.txtStudentId & ".jpg"

Above assumes the folder containing the student photos is found on your
C drive and is named "StudentPhotos".

You will need to add error handling to allow for the situations where
there is no corresponding StudentPhoto for the current record. Generally
you would create a blank Photo containing the Text "Not Avail" or
something similiar. Use the DIR command to check for the existence of
the Student Photo and then load the Not Avail photo if no file is found.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

I can not find the Standard Image Control. The only image control tool I have
only lets me insert a picture. Did I miss something? I did get the text box
to change when I selected another item. But the picture remains the same, and
to make it worse it is my vice principal. (He is a great guy though)
I have the table with the picture locations built. I used the help file but
the problem with the image control is something different.

Thanks for your patients.
 
S

Stephen Lebans

There are three possible controls on your ToolBox that can display
pictures. As I stated in my first reply,

The control you want is named "Image". AS you hover your Mouse overtop
of the ToolBox controls it will show you the name of each control. I
honestly do not know what else to tell you
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

I have found the Image tool. Every time I select it we go to an insert area
and I have to select a picture? I have seen a icon for more controls but
there not controls that say standard image? Sorry I am so dense, thanks for
your replys and help.
 
S

Stephen Lebans

Yes it is the Image control and you do have to initially select an Image
to load into the control. Just select your "Not Available" image we
discussed earleier. It does not matter for now.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
L

luca

Stephen Lebans said:
Hi Andrew,
I'm assuming you have a field in your table that contains the Student ID
#'s used to name the Jpegs. I'll also assume that you have a TextBox
control on your form that is bound to this StudentID field and is named
txtStudentID.
Place the standard Image(NOT Bound or Unbound Object Frame) control on
your form, name it ImagePhoto.

In the Form's Current event do something like:
Me.ImagePhoto.Picture = "C:\StudentPhotos\" & Me.txtStudentId & ".jpg"

Above assumes the folder containing the student photos is found on your
C drive and is named "StudentPhotos".

You will need to add error handling to allow for the situations where
there is no corresponding StudentPhoto for the current record. Generally
you would create a blank Photo containing the Text "Not Avail" or
something similiar. Use the DIR command to check for the existence of
the Student Photo and then load the Not Avail photo if no file is found.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

It did not work. I still have only one picture. The text box changes to
reflect the location of the student pictures but the picture does not change.
I already have the locations saved on the table, is there an easier way? It
was easy to use an update query and do that, but the picture is now the mess.
I still see the same picture and only the text box changes.

Thanks
 
S

Stephen Lebans

So you have a TextBox control bound to the StudentID field and you can
see that as you scroll through t he records that the contents of this
TextBox display the proper StudentID?

Copy and paste all of the code you have in your Form's CLass module.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

Yes I have the complete path to the images on a table. Now all I need to do
is get the picture to be the same as the student number.
 
S

Stephen Lebans

Where is the code behind your Form that I asked you to post?

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

Option Compare Database

Private Sub Form_Current()
Me.ImagePhoto.Picture = "C:\StudentPhotos\" & Me.txtStudentID & ".jpg"
On Error Resume Next
End Sub

I hope that this is correct. It runs but now the error messages says that
Access can not open the file C:\StudentPhotos\(a student number).jpg?
It then directs me back to the code page.
 
S

Stephen Lebans

Well it sounds like the StudentID field is not returning a value that
can be linked to an existing Student Photo. When the Error is generated
you are placed back in VB IDE with the offending Line of code
Highlighted. Can you check the value of Me.txtStudentID? Is there an
exitisting photo that matches this ID?

Also we need to add error checking to allow for such conditions as "no
such student photo on file", etc. I'll dig something out of the NG
postings later tonight.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
S

Stephen Lebans

Let's add some logic to your function to handle the situation when there
is NO matching Student Photo for this particular StudentID. Erase what
you have in the Form's Current event and replace with the code below.

Private Sub Form_Current()

Dim sFileName as string

sFileName = "C:\StudentPhotos\" & Me.txtStudentID & ".jpg"

' See if this photo exists
' Returns a zero length string if file does not exist
sFileName = Dir(sFileName)

If len(sFileName & vbNullString) = 0 Then
' Load "Not Available" Photo
Me.ImagePhoto.Picture = "C:\StudentPhotos\NotAvailable.jpg"
Else
' Load the matching Photo for this StudentID
Me.ImagePhoto.Picture = sFileName

End if

End Sub



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

Stephen;
Thanks for the help. It is working. As I played with it I found that I had
to format the Student ID numbers so they matched. Some were only 3, 4, 5, and
6. I used an update query and the FORMAT command and gave the shorter ones 0
to make them 6 digits. That is the way the bar coder needs them so they have
been stored as 6. I also looked at using the same type of query to build a
text file with the picture location. It worked but has the same problem about
not having a jpg and trying to use a student number. I will work the error
statement out eventually. We will be using this for security at our
graduation in June. It has been a real help, I thank you again.
 

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