picture help

A

Afrosheen

I have a form called frmpictframe. It has a picture frame inside the form
called imgEmpty.
I have on the form_current event: Me!imgEmpty.Picture = CurrentProject.Path
& "\NCI Pictures\" & Me!IdPict.Value. It works great if there's a picture. If
there isn't it gives me an error.

I put an on error code in it and that works. The problem is the error works
too good. It will even trigger if the picture is there.

What I want to to is create a statement when I add a new record and the
picture is not there then the field for the picture {idpict} will default to
"na.bmp" and will not create the error and display.

Here's what I have. Any suggestion woulds help

If IdPict = " " Then
IdPict = "na.bmp"
Endif

Me!imgEmpty.Picture = CurrentProject.Path & "\NCI Pictures\" &
Me!IdPict.Value

This is not working.

Thanks for your help.
 
R

Rob Parker

Try this:

If (IdPict & "") = "" Then
IdPict = "na.bmp"
Else
Me!imgEmpty.Picture = CurrentProject.Path & "\NCI Pictures\" &
Me!IdPict.Value
End If

The construction in the If condition will test for both null and zero-length
string in IdPict.

The code you posted doesn't have any error handling associated with it, so I
can't really tell you what the problem there is. But it's likely that
you've omitted the Exit Sub statement which should appear before the
error-handling code. Your routine should have the following structure:

Private Sub Control_Event()
On Error GoTo Control_Event_Error
' code for routine
Exit Sub

Control_Event_Error:
' code for error handling
End Sub

HTH,

Rob
 
A

Afrosheen

Hi Rob, Thanks for your reply.
It works great but it created another problem. When I click on the new
record, it does add the na.bmp. Where the problem comes is when I add the
information and look at the table there are two new records. That may be in
my programming and I'll have to check it out.

Thanks again

Here is the complete code:

Private Sub Form_Current()
On Error GoTo Err_Form_Current

If (IdPict & "") = "" Then
IdPict = "na.bmp"
End If

Me!imgEmpty.Picture = CurrentProject.Path & "\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.", vbExclamation,
Application.Name)
End Sub
 
R

Rob Parker

The problem of two additional records is not related to the issue of
displaying a picture in an image control. If you can't find what's causing
the problem, I suggest you post again with a subject line that describes
that problem.

Rob
 

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