Help with Error response

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I have the below code and I want to respond to the user with a message if the
ImagePath is not found. I want to be clear - so if the user clicks on the
ItemComponent and the path is not found it pops up and asks the user to debug
or end. What I'd like it to do is pop up and say path or image not found. Not
sure what the code would be to do this.. Can anyone help. Thanks

Private Sub ItemComponent_Click()

If Me.FileType = "jpg" Then
If IsNull(Me.[ImagePath]) Then
Forms!frmItemCompEntry!ImageData.Visible = False
Forms!frmItemCompEntry!lblNoImage2.Visible = True
Forms!frmItemCompEntry!lblNotJpg.Visible = False
Else
Forms!frmItemCompEntry!ImageData.Picture = [ImagePath]
Forms!frmItemCompEntry!ImageData.Visible = True
Forms!frmItemCompEntry!lblNoImage2.Visible = False
Forms!frmItemCompEntry!lblNotJpg.Visible = False
End If
Else
Forms!frmItemCompEntry!lblNotJpg.Visible = True
Forms!frmItemCompEntry!lblNoImage2.Visible = False
Forms!frmItemCompEntry!ImageData.Visible = False
End If

End Sub
 
B

Beetle

You can add error handling to your code and trap for the error number.
I don't know what error number you're actually getting, so the below is
just an example;

Private Sub ItemComponent_Click()
On Error GoTo HandleError

If Me.FileType = "jpg" Then
If IsNull(Me.[ImagePath]) Then
With Forms!frmItemCompEntry
!ImageData.Visible = False
!lblNoImage2.Visible = True
!lblNotJpg.Visible = False
End With
Else
With Forms!frmItemCompEntry
!ImageData.Picture = [ImagePath]
!ImageData.Visible = True
!lblNoImage2.Visible = False
!lblNotJpg.Visible = False
End With
End If
Else
With Forms!frmItemCompEntry
!lblNotJpg.Visible = True
!lblNoImage2.Visible = False
!ImageData.Visible = False
End With
End If

Exit_Here:
Exit Sub

HandleError:
If Err.Number = 3201 Then
MsgBox "Invalid path. Please try again."
Resume Exit_Here
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
End If

End Sub
 
A

aceavl via AccessMonster.com

if you just want to tell the user that the image doesn't exist and if he
wants to debug, you could use something like this:
dim intVar as Integer
intVar = MsgBox("Image not found. Do you want to debug?", vbYesNo, "Not
Found")
If intVar = vbYes Then
'debug
Else
'don't debug
End If
 

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