Please check code

A

Afrosheen

I have in my table a field for my image file name called IdPict. I also have
a form with a picture box called imgEmpty. When try to access the picture it
always says that the picture is not found when the picture is there. The
drive and locations are valid. It will display the picture, but it comes up
with the error MsgBox. Could you please go over the code? Any suggestions
would be appreciated. I do want the error code in it if possible because when
enter a new record and the picture is not there then it will add a default
"No Picture"
Thanks

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Me.imgEmpty.Picture = "g:\NCI Database\NCI Pictures\" & Me!IdPict.Value

Err_Form_Current:
Call LogError(Err.Number, Err.Description, "Form_Current()")
Call MsgBox("Picture was not found on this drive. A generic picture has
been added", vbExclamation, Application.Name)
'IdPict = "na.bmp"
End Sub
 
B

boblarson

Well, the first is that you need to exit the procedure before the error
handler (see addition between ######:

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Me.imgEmpty.Picture = "g:\NCI Database\NCI Pictures\" & Me!IdPict.Value
'###############
Exit Sub
'###############
Err_Form_Current:
Call LogError(Err.Number, Err.Description, "Form_Current()")
Call MsgBox("Picture was not found on this drive. A generic picture has
been added", vbExclamation, Application.Name)
'IdPict = "na.bmp"
End Sub
--
Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP

Tutorials at http://www.btabdevelopment.com

__________________________________
 
K

Klatuu

Any time you have an error handler routine in a procedure, you have to exit
the sub before the error handler. The On Error GoTo statment will branch the
code to the error handler tag when an error occurs. In this case, you need
to also check the error code to be sure the message you are displaying is
correct. It is possible some other error could occur and you would be
displaying a misleading message.

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Me.imgEmpty.Picture = "g:\NCI Database\NCI Pictures\" & Me!IdPict.Value

Exit Sub

Err_Form_Current:
If Err.Number = ???? Then (Don't know the number, you will have to
include it)
Me.imgEmpty.Picture = "g:\NCI Database\NCI Pictures\na.bmp"
MsgBox("Picture was not found on this drive. A generic picture has
been added", vbExclamation, Application.Name)
Else
Call LogError(Err.Number, Err.Description, "Form_Current()")
End If
End Sub
 

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

Similar Threads


Top