Adding picture to database


G

Guest

I want to add a picture to a record in the database. I have tried creating a
field as an OLE object but with no luck. What is the best way, fastest
access, disk space etc. to add a image to a record in your database? Thanks
for the help.
 
Ad

Advertisements

S

strive4peace

The best way is to store the path and filename as text and
render the image when you want to see it. Storing OLE
objects is a really fast way to bloat the database and it is
much more efficient to store images as JPG files

for forms:

put this OnCurrent and the AfterUpdate event of the control
to store your file path name and filename:

'~~~~~~~~~~~~~~~

dim mBoo as boolean
mBoo = true
if isnull(Me.FileImage_controlname) then
mBoo = false
else
if Dir(Me.FileImage_controlname) = "" then
mBoo = false
end if
end if

Me.FileImage_controlname.Visible = mBoo

if mBoo then
Me.FileImage_controlname.Picture = _
me.filePathAndName_controlname
Me.FileImage_controlname.Requery
end if

'~~~~~~~~~~~~~~~

for reports:

this goes in the OnPrint event of the section your image
control is in:

'~~~~~~~~~~~~~~~

Private Sub Detail_Print(Cancel As Integer, PrintCount As
Integer)

With FileImage_controlname
If Dir(nz(Me.filePathAndName_controlname),"") <> "" Then
.Visible = True
.Picture = Me.filePathAndName_controlname
Else
.Visible = False
End If
End With

End Sub
'~~~~~~~~~~~~~~~

the code is logically the same for both methods -- just
wrote it a little different

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
G

Guest

Thanks Crystal: I am a bit of a rookie with Access. Can you explain this
method in either more details or simpler for me. I just use the basics,
mostly using wizards. I can modify forms and reports in design view but thats
about it. Any extra help will be appreciated.

Thanks
 
E

Edward Reid

AJK,

Someone who's an expert (unlike me) can perhaps explain all the
nitty-gritty. Here's what I know about the basics.

Access does not have the concept of a linked image as a database
(table) field. However, it has text fields (in which you can store the
path) and it has "image controls", which are form and report objects
rather than table fields. The trick is to store the path in a text
field and use event procedures to set the .Picture property of a form
or report at the critical point when it's time to display the image.

In effect, the code causes Access to use the Image Control (in the form
or report) as a conduit for displaying the image which is at the path
pointed to by the text field in the current record.

The other trick you see in Crystal's code is to make the image control
not Visible when there is no image available. The code is carefully
designed to yield this result if either 1) the path field is null in
the current record, or 2) the path/file it points to does not exist.
I'm not sure what happens if you make an image control Visible with its
Picture property pointing to a non-existent file, but I'm sure it isn't
pretty. ;-)

Edward
 
S

strive4peace

Hi Edward,

great explanation!

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
S

strive4peace

Just like in the real world, every object has properties and
methods.

Properties describe an object
Methods define actions an object can do

For instance, you are a human and have properties such as
hair color, eye color, height, weight, ... and methods such
as eat, run, jump, ...

In the design view, you can show the property sheet, which
will show informtion for the selected item(s).

Try it!

when you are in the design view, turn on/off the Properties
window --> View, Properties from the menu

and then click on various objects.

You can get help about any property by pressing F1 while
in the property you want more information on.

OnCurrent is an EVENT property (actually METHOD since it is
an action) of the form

To select the form, you may click in the upper left corner
where the rulers intersect or click completely outside the
designed area in the dark gray space. You can also press
CTRL-R or Edit, Select Form.

To build an event, click in the property sheet for the
appropriate object in the appropriate location and then
click the builder (...) button off to the right

Access will provide the procedure declaration and the
procedure end -- you put the lines in between.

Procedures are NAMED according to the object name (except
the form object), so ALWAYS change the NAME property of any
object to something logical.

Explore the property sheet. Get familar with how properties
are grouped on the tabs and the different properties for
different objects.

For general help about Access, I find it interesting and
informative to read the help starting from the beginning of
the Contents. In fact, if you have the desire to print a
ream of paper, it would be good to print it like a book and
read it.


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Ad

Advertisements

Ad

Advertisements

S

strive4peace

you're welcome, Joe :) happy to help

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 

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