Where to trap the error?

F

Fred Boer

Hello:

I have a splash form with an image control. The image is linked, not
embedded. Suppose the linked image file is deleted. Access can't find the
picture and throws an error. I believe the error number is 2220. Where do I
trap this error? I've tried the usual suspects.. On Error, On Open, On
Activate, On Load, but on opening the form, the error seems to come before
any of these. I'd like to substitute a custom error message...

I am trying to give users the ability to customize a picture on the main
switchboard form. My idea is to have a hidden "default" picture which I'd
use if the "custom" picture isn't available for some reason. I'd flip their
visibility. The "default" picture would be embedded, so it couldn't be lost.
If I could trap the error when the custom picture is missing, I'd be able to
ignore the error and just pop up a custom messagebox, and use my default
picture. Is this a reasonable way to do it?

I thought about storing a default picture in a field in a table and doing a
DLookup in some way, but I can't even seem to store a picture so that it
shows up on a form properly...


Thanks!
Fred Boer
 
D

Douglas J. Steele

How are you linking the picture to the image control? Can you use the Dir
function to determine whether or not the file actually exists?
 
F

Fred Boer

Hello Doug!

I am linking the picture to the image control by setting the path to the
image file in the properties of the image control.. i.e. Format>Picture.
Thanks, I do know about using the Dir function, but I can't seem to find an
event that I can use to trap the error; as soon as the form opens, the error
is thrown before I can get my foot in the door to do anything...

This is the splash form, i.e. the first form that opens in the
application...

Are you suggesting that I might open some hidden form first, and check for
the existence even before opening the splash form?

Cheers!
Fred
 
D

Dirk Goldgar

Fred Boer said:
Hello Doug!

I am linking the picture to the image control by setting the path to
the image file in the properties of the image control.. i.e.
Format>Picture. Thanks, I do know about using the Dir function, but I
can't seem to find an event that I can use to trap the error; as soon
as the form opens, the error is thrown before I can get my foot in
the door to do anything...

This is the splash form, i.e. the first form that opens in the
application...

Are you suggesting that I might open some hidden form first, and
check for the existence even before opening the splash form?

Suppose you set the image control's Picture property in the form's Open
event, after you've determined whether the image file exists or not?
 
F

Fred Boer

Hi Dirk:

Access won't let me...if I try to leave the Picture property blank, Access
assumes I want to delete the control...


Cheers!
Fred
 
R

Rick Brandt

Fred Boer said:
Hi Dirk:

Access won't let me...if I try to leave the Picture property blank, Access
assumes I want to delete the control...

Put in a file reference initially when creating the control and then remove it
afterwards. I just tried this and it did leave the control as just a blank
rectangle on the form.
 
F

Fred Boer

Wait.. sorry, Dirk. When I ignored the warning about deleting the picture, I
see that the empty frame (is that what it is called?) remains...

Ok, so, if I can set the picture on opening the form, I think that solves
the problem. I'll try it and post back if I have any problems, but I think
that'll do it!

Thanks to you and Doug!

Fred
 
D

Dirk Goldgar

Fred Boer said:
Hi Dirk:

Access won't let me...if I try to leave the Picture property blank,
Access assumes I want to delete the control...

As Rick said: create the control with a file reference; then delete
the reference afterward.
 
F

Fred Boer

Thanks, Rick. Yes, that works. I hadn't actually tried it to see what would
happen...

Cheers!
Fred
 
D

Douglas J. Steele

Put the default picture there, and overwrite it once you know that the
picture you want actually exists.
 

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