Insert picture

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got three columns:
first_name,
last_name,
p_picture.

There are pictures stored on disk named like "last_name first_name
date_of_birth.jpg"

I need insert picture into the column p_picture with appropriate name
consisting of values from columns first_name and last_name.
 
Hi catchy,

What version of Access are you using?

If <2007, are you storing the picture file as a text field? It is
better to do this than to store OLE objects as they cause database bloat.

If you store a text path and filename, you can render the image when you
pull the record from the stored path and filename (or, if your JPG files
are in a known directory, you can construct the filename from your data).


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
1) Access 2003
2) pictures are stored as OLE objects
3) I am newbie, could you be more specific?
4) filename will be constructed only from last_name and first_name

„strive4peace" napísal (napísala):
 
Hi,

It's a bad idea to store pictures as OLE objects. Take a look at Northwind
Sample db shipped with Access. Have a glance at Employees table and form.
That will give you pointers as to how to store only the path to the pictures
as text field.

for setting the name of the picture, you can simply concatenate:

txtPicture = "Path to Picture" & "\last_name" & "first_name" & ".jpg"

Hope that helps.
 
Hi Catchy,

to elaborate on what Sreedhar wrote:

txtPicture = "Path to Picture" & "\last_name" & "first_name" & ".jpg"

and what you said earlier:

There are pictures stored on disk named like "last_name first_name
date_of_birth.jpg"

to get Access to use what is IN the controls instead of literally
specifying last and firstname...

PathAndFilename = "Path to Picture" & "\" _
& [last_name_controlname] & " " _
& [first_name_controlname] _
& format([date_of_birth_controlname],"mm/dd/yy") _
& ".jpg"

(space underscore at the end of a line of code means that statement is
continued onto the next line)

I couldn't tell if there is a space before the names and the date (the
example left it out)... it is not a good idea to use spaces anyway, nor
is it good to use special characters such as slashes

Personally, when I use a date in a filename, I use this format: yymmdd

ie: Aug 7, 2006 --> 060807

and instead of space, use the underscore character _

if you already have a bunch of files stored with these names, it is
simple to write a little routine to go name them better... and if you
need help with that, just let us know


once you have the filepath and name constructed (btw,
currentproject.path gets the path of your database), you can do this:

'~~~~~~ in a report:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
With controlname_for_image
If Dir(Me.controlname_with_path_and_filename) <> "" Then
.Visible = True
.Picture = Me.controlname_with_path_and_filename
Else
.Visible = False
End If
End With
End Sub

if you are using a variable to construct the path and filename,
substitute it in for
Me.controlname_with_path_and_filename

the image control is the icon on the toolbox with the mountains and the sun

'~~~~~~ on a form:

you use the same method, and call the code on the form Current event as
well as the AfterUpdate event of any control that affects the filename
or filepath


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
Catchy,
were you able to figure out what these guys are saying?
You can place the image object on your form and load it with linked pictures.
The following is a sub that calls a sub to change the picture diplayed on
the form.
_________________________________________________________________
Private Sub CallLoadImage()
Call LoadImage("last_name_first_name.jpg")
End Sub

Private Sub LoadImage(strPicName As String)
Me.Image1.Picture = "C:\MyPix\" & strPicName
End Sub
_____________________________________________________
 
Hardly :)

Filenames do not strictly contain date neither strictly in format
"year/month/day".

What I really need is routine which populates OLE object cells with
appriopriate images.

I am able to construct the correct filename, but I do not know method to
insert picture (via packager ???) into the cell.


„sparker" napísal (napísala):
 
Hi Catchy,

"What I really need is routine which populates OLE object cells with
appriopriate images."

please, read what I have written -- print it out, take it it the
bathroom... read it before you sleep (a great time to learn)... unless
you are using Access 2007, you do NOt want to store OLE objects... I
KNOW it can be frustrating, but try and ask... we are here to help you.

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
Catchy,

I am not sure what the first sentence of your response is supposed to mean.
I can only assume you may also be needing some assistance with date and
string functions or more specificaly converting dates into strings maybe?
Anyway back on track with your original posting... Everyone is in agreement
that you should not put the pictures in the database but a better solution is
to put the names of the pictures in a table in your database. In other words
if you put all of your pictures in a folder let us pretend that they are on
your desktop in a file called pix. You can then store all of the picture
names in a table now your form that will display the images will need to
have an image object on it. You then have the ability to load any of the
pictures you want in to the image object. Lets say you have a drop down with
the names. You would use the afterupdate to load the image. If this is not
what you are wanting or is of no help at all please forgive me then I must
completely not understand what you are doing. However, if you are also
needing help with string and date functions just say the word.
CSTR(Format(DATE(),"yyyymmdd"))
the above line would produce a text string you could use in your pictures
name and or address like "20060808" Hang in there eventualy we will figure
out how to help!
 
catchy said:
Filenames do not strictly contain date neither strictly in format
"year/month/day".
I am able to construct the correct filename.

If your Pic filenames won't stick to a format based on the data you have in
your table, relating the pictures to the correct record will have to be done
manually i.e., you choose every pic and put it in the related record in the
table (OLE or NOT is upto you).If you have already a lot of records in your
table, that's a lot of work.

If you still managed to pull up the correct files through code, can you
please explain how you were able to do that, so that I can benefit from your
efforts ?

If I didn't get it right, nevermind this post.
 
Hi Catchy,

even though you have gone past this, I wanted to point it out for
someone else reading the thread...

format([date_of_birth_controlname],"mm/dd/yy")

would not be allowed in a filename because of the slashes ... should
have used dashes in my example but, as I said, it is best to remove the
delimiters completely and pack the date into just numbers...

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*


Hi Catchy,

to elaborate on what Sreedhar wrote:

txtPicture = "Path to Picture" & "\last_name" & "first_name" & ".jpg"

and what you said earlier:

There are pictures stored on disk named like "last_name first_name
date_of_birth.jpg"

to get Access to use what is IN the controls instead of literally
specifying last and firstname...

PathAndFilename = "Path to Picture" & "\" _
& [last_name_controlname] & " " _
& [first_name_controlname] _
& format([date_of_birth_controlname],"mm/dd/yy") _
& ".jpg"

(space underscore at the end of a line of code means that statement is
continued onto the next line)

I couldn't tell if there is a space before the names and the date (the
example left it out)... it is not a good idea to use spaces anyway, nor
is it good to use special characters such as slashes

Personally, when I use a date in a filename, I use this format: yymmdd

ie: Aug 7, 2006 --> 060807

and instead of space, use the underscore character _

if you already have a bunch of files stored with these names, it is
simple to write a little routine to go name them better... and if you
need help with that, just let us know


once you have the filepath and name constructed (btw,
currentproject.path gets the path of your database), you can do this:

'~~~~~~ in a report:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
With controlname_for_image
If Dir(Me.controlname_with_path_and_filename) <> "" Then
.Visible = True
.Picture = Me.controlname_with_path_and_filename
Else
.Visible = False
End If
End With
End Sub

if you are using a variable to construct the path and filename,
substitute it in for
Me.controlname_with_path_and_filename

the image control is the icon on the toolbox with the mountains and the sun

'~~~~~~ on a form:

you use the same method, and call the code on the form Current event as
well as the AfterUpdate event of any control that affects the filename
or filepath


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*


Hi,

It's a bad idea to store pictures as OLE objects. Take a look at
Northwind Sample db shipped with Access. Have a glance at Employees
table and form. That will give you pointers as to how to store only
the path to the pictures as text field.

for setting the name of the picture, you can simply concatenate:

txtPicture = "Path to Picture" & "\last_name" & "first_name" & ".jpg"

Hope that helps.
 
"catchy" wrote
1) Access 2003
2) pictures are stored as OLE objects
3) I am newbie, could you be more specific?
4) filename will be constructed only from last_name and first_name

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.

Larry Linson
Microsoft Access MVP
 
Back
Top