Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

avoid error 2220 1

Status
Not open for further replies.

davyre

Programmer
Oct 3, 2012
197
AU
Hi,

I have a piece of code to display a picture in an Access Form. Here's the code:
Code:
Dim UnitID As String

UnitID= Me.UnitID.Value

If IsNull(UnitID) = False Then
    Me.ImageBox.Picture = "E:\User\USER\Database\Unit Pics\" & UnitID & ".png"
Else
    Me.ImageBox.Picture = "E:\User\USER\Database\Unit Pics\rduck.jpg"
End If
ListUnitPart.Requery

The problem is if a picture for a particular unit is unavailable, it will show error 2220 unable to open (of course, because the file does not exist). What I want is if that happen, instead of spitting out error message, it will replace the pics with rduck.jpg (as in ELSE clause). Any help? Thanks!
 
One way:
Code:
Dim UnitID As String
UnitID = Dir("E:\User\USER\Database\Unit Pics\" & Me!UnitID & ".png")
If UnitID = "" Then UnitID = "rduck.jpg"
Me!ImageBox.Picture = "E:\User\USER\Database\Unit Pics\" & UnitID

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top