Optional image vs. OLE

G

Guest

I understand that using the Image control, storing the image path in a text
field, and loading the image at runtime is superior (spacewise) to using an
object frame bound to an OLE field, but I have two questions:

1. Since, in my application, it is up to the user to import an image or
leave it empty, how do I hold the place/size of the Image control when it has
no image? Should I just provide a default image of a jpeg that says "No image
selected" and insert that by default and if the user elects to remove the
reference to the image?

2. What if the user moves the image file? What code could I insert in the
report that includes a reference to this image to ensure that the image is
simply omitted if it is not found rather than generating an error? Would this
be:

If Len(Dir(<Stored path/filename>)) = 0 Then...?
 
G

Guest

I did both of these, but since this is an app that I am distributing to
clients form whom I do not provide any infrastructure support, I cannot
guarantee that the default file will be or stay in the default location, nor
even that their default location will be the same (assuming it will be on a
mapped drive).

Certainly, my help files will indicate that the image files should be placed
on the server so that they are accessible by the user regardless of which
workstation he chooses to use (assuming the drive mapping is consistent).

The table that contains the user profile has a field for the path/filename
to that user's image file, but the entry will be null by default and will
only be populated if the user browses for selects an image file (using the
comdlg32 API call).

On the open event of the user options form, I set the image control's
..Picture property to the filepath string from the current user's profile in
the table (if the pathname has been set). However, I still had to hard-code
the .Picture property when saving the form, because the Image control will
not remain on the form without a valid image path.

I was hoping that there would be a way embed the default image in the
database so that I could have the Image control load that one if the user
does not have one. However, it appears that the .Picture property can only be
a reference to an external image file, not to an image file embedded in the
database. I did make a workaround for those cases when neither the user's
image file or the default cannot be found (but I just don't like
workarounds, and I may not be foreseeing the time when someone manages to do
something that actually removes the control from the form because there is no
valid image file found):

-Trap & ignore the 2220 error that occurs in this case
-If the user has no image file in his profile, and if the default image file
is not found at the hard-coded location, do the following two things:

-Set the image control's .Visible property to False
-Overlay a text box (containing a note about how to link to an image file)
over the image control, and set its .Visible property to True
If a valid image file is found, vice versa both of the above.

If I am just making this too difficult, please let me know of an easier way.
I'm trying to prevent the "Just get MS Photo Editor off your Office 2000
disk" fix that I might have to try to sell to the client if I go with OLE, as
well as the file bloat that occurs from embedding pictures.
 
S

Stephen Lebans

A couple of methods are available:

1) Add a hidden Image control to the form in question. Load your "default
Picture" into this control. Your statement is incorrect that the Image
control cannot contain an Image without a valid/existing path. In design
view, once you select an Image via the control's Picture property, it
remains embedded.
Now whenever you want to display the defaul pic simply do something like:
Me.ThisFormsImageControl.PictureData =
Forms!NameOFtheHiddenForm.ImageControl.PictureData

or

2) Load the default pic into an Image control.
Copy the control's PictureData property to a table containing a Long Binary
field
When you want to display the default pic simply copy the contents of the
field to the PictureData prop of the desired Image control.

--

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

Guest

Thank you, Stephen. What I meant is that one cannot remove/nullify the
..Picture property because Access assumes that you are trying to remove the
control (and rightly so, I guess, since it is, after all, an image). I
noticed that once set to a valid path it is persistent, even if the file is
later removed. By either trapping the 2220 error or doing On Error Resume
Next, I can get past the error that is generated if it is linked but the file
is not found. Every time I drop into design view, however, I get a message
indicating that Access could not open the file.

That is a minor nuisance, though. I assume in your #1 that you mean to embed
the image in the hidden control so that it is available for the other one. Is
either of these two options more efficient than the other?
 

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