Discussion:
Storing and displaying pictures with MS Access -D7
(too old to reply)
Jacques
2005-04-30 14:52:35 UTC
Permalink
Does anyone one know how to store and retrieve pictures(jpg,bmp etc) in a
Access database? I tried to follow a tutorial on it at
http://delphi.about.com but that example does not seem to work.

Can anyone help?
Thanks
ielite
2005-04-30 15:12:29 UTC
Permalink
Really, I used that same exact titorial and it works for me great!

What exact errors or problems are occuring for you?

sholmes
Post by Jacques
Does anyone one know how to store and retrieve pictures(jpg,bmp etc) in a
Access database? I tried to follow a tutorial on it at
http://delphi.about.com but that example does not seem to work.
Can anyone help?
Thanks
ielite
2005-04-30 15:20:20 UTC
Permalink
Here is a couple snipplets from my code:

from field to TImage

TBlobField(form2.table1.FieldByName('Image')).Assign(form1.image1.Picture.Bitmap);

from TImage to Field

form1.image1.Picture.Bitmap.Assign(TBlobField(form2.table1.FieldByName('Image')));

Hope this helps!

sholmes
Post by ielite
Really, I used that same exact titorial and it works for me great!
What exact errors or problems are occuring for you?
sholmes
Post by Jacques
Does anyone one know how to store and retrieve pictures(jpg,bmp etc) in a
Access database? I tried to follow a tutorial on it at
http://delphi.about.com but that example does not seem to work.
Can anyone help?
Thanks
Keith G Hicks
2005-04-30 15:40:47 UTC
Permalink
If I might make a suggestion (I've done a lot of work in MS Access), don't
store the images in Access tables if you can avoid it. At least up through
version 2k, OLE fields seem to be sort of unstable depending on your setup
(network and such).

I have 2 big Access apps out there that make extensive use of images.

One of them stores thousands of images of CD cover art (for a music
catalog). The original programmer stored the images in the tables. They had
speed issues and corruption issues and the mdb was unecessarily huge. So we
changed it to store the images as jpg or bmp files in a folder on the server
and reference them by some naming strategy. For the music catalog we saveed
the image files with a file name that matched the catalog number of the CD.

The other program stores the image files with a file number that matches the
part number of the item in question. When that part or CD is called up on
a form or a report, we simply look for the associated image on disk and show
it. (of course you can add code to allow users to use a different image or
even call up some image editing too also).

As a matter of fact I also just wrapped up an MS Access/ SQL 2000 program
where we store pdf files on disk and create list boxes of the files for each
client record. The user can double click an item in the list and Acrobat
reader opens up so they can veiw the file. In that system we have a series
of folders for each client where the folder name simply matches the primary
key of the client record.

All of these work very smoothly. One thing I need to mention however is that
if you use jpg files, there is a small delay sometimes (depends on your
system resources) when opening up a form or report due to the system having
to decompress the file to display it. If a user clicks through records too
fast, sometimes an error occurs if the file has not had time to decompress.
We just worked around the error.. Of course bmp files do not produce such a
delay but then they take up a lot of disk space.

Of course if catalog or part numbers are able to change then you need code
to change the associated file names as well. We did that for the pdf work.
Not a big deal.

Here's my Access function that retrieves the image file for use on a form or
report:

Public Function fncSetImageFile(varFileName As Variant, strFileExt As
String)
On Error GoTo Err_fncSetImageFile

Dim bolFileFound As Boolean
bolFileFound = False

'set the image file to the default of none available.
fncSetImageFile = "ImageNotAvailable"

If IsNull(varFileName) Or varFileName = "" Then
'if there is no image file name passed, use the setting from above.
Else
If Dir(strImageFilePath & varFileName & strFileExt) = "" Then
'If there is a file name passed, but it does not exist on disk,
leave it as it was set above (no image file)
Else
bolFileFound = True
'the file name is passed and it is indeed found on disk.
End If

If bolFileFound Then
fncSetImageFile = strImageFilePath & varFileName & strFileExt
End If
End If

Exit_fncSetImageFile:
Exit Function

Err_fncSetImageFile:
If Err.Number = 3021 Then
GoTo Exit_fncSetImageFile
End If
MsgBox Err.Description & ": " & Str(Err.Number)

End Function

And here's the calling routine in one of the form on current event:

'get the image files
If fncSetImageFile(Me!PartNumber, ".bmp") = "ImageNotAvailable" Then
Me!lblPartImageNotAvailable.Visible = True
Me!PartImage.Visible = False
Else
Me!lblPartImageNotAvailable.Visible = False
Me!PartImage.Visible = True
Me!PartImage.Picture = fncSetImageFile(Me!PartNumber, ".bmp")
End If

PartImage is just an Image object.

HTH,

Keith

"Jacques" <***@btinternet.com> wrote in message news:***@newsgroups.borland.com...
Does anyone one know how to store and retrieve pictures(jpg,bmp etc) in a
Access database? I tried to follow a tutorial on it at
http://delphi.about.com but that example does not seem to work.

Can anyone help?
Thanks
Andrew
2005-04-30 23:14:10 UTC
Permalink
Post by Jacques
Does anyone one know how to store and retrieve pictures(jpg,bmp etc) in a
Access database? I tried to follow a tutorial on it at
http://delphi.about.com but that example does not seem to work.
Can anyone help?
Thanks
Keith makes a valid point and for many images, we also use the same system
of just storing filenames in the database. If you only want to work with
smallish images, I suggest that you access the blob field using the
savetostream / loadfromstream methods. Use these to then load your visual
image component.
eg: TBlobField(MyDB.FieldByName('images')).SaveToStream(ms) //ms is a
temporary TMemoryStream
then load the image from ms:

ms.position:=0;
theimageobject.LoadFromStream(ms);

Alternatively, you can use TBlobStreams to load/save info into the blobfield
eg:

bs: TBlobStream;

bs:=MyDB.CreateBlobStream(MyDB.FieldByName('images'),bmRead);
theimageobject.LoadFromStream(bs);

Check out Delphi help for some of the caveats when using TBlobStreams

HTH

Andrew
Brian Bushay TeamB
2005-05-01 01:41:16 UTC
Permalink
Post by Jacques
Does anyone one know how to store and retrieve pictures(jpg,bmp etc) in a
Access database? I tried to follow a tutorial on it at
http://delphi.about.com but that example does not seem to work.
That tutorial works where are you having the problem?
--
Brian Bushay (TeamB)
***@NMPLS.com
GP
2005-05-01 03:14:51 UTC
Permalink
I just upload a small sample on how to store and play wave audio in ms
access, hope that give you an idea.
Check the method copyfrom.

Saludos.
Gilbert
Maravilla Software
Post by Jacques
Does anyone one know how to store and retrieve pictures(jpg,bmp etc) in a
Access database? I tried to follow a tutorial on it at
http://delphi.about.com but that example does not seem to work.
Can anyone help?
Thanks
Loading...