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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handler Not Firing 1

Status
Not open for further replies.

FastLearnerIThink

Technical User
Jun 9, 2005
37
DE
I have developed a DVD collection database with pictures. Whenever an error occurs, the error handler does not fire up. Can someone please look at my code and tell me why this may be so?

Code:
Private Sub Form_Current()
On Error GoTo Handle_Error
If Not IsNull(Me.txtRegionCode) Then
    Me.txtRegionDesc = DLookup("[fldRegionDesc]", "[tblRegion]", "RegionCodeID = " & Me.txtRegionCode)
End If
If Not IsNull(Me.txtImagePath) Then
    Me.imgCover.Picture = Me.txtImagePath
Else
    Me.imgCover.Picture = ""
End If

Handle_Error:
    MsgBox "Executing Error Halt, Error: " & Err.Number & vbCrLf & _
    "Description: " & Err.Description
End Sub

The most common error is when the image is moved and the image path is no longer correct. I tried to capture it, error 2220, and tell it what to do, but program still stops and highlights the me.imgCover = me.txtimagepath line. Even after chnging it to the code above, it still won't fire up.

Any help will be appreciated. Thanks.

-- Fast Learner, I Think

Here's something to think about. How come you never see a headline like 'Psychic Wins Lottery!'? - Jay Leno
 
Thanks for your response. I can't figure out why either as I don't see anything wrong with the code.

Even with the exit sub prior to the error, still the same issue. Only difference is that I get an error 0 when switching records without placing the exit sub line before the error handler.

-- Fast Learner, I Think

Here's something to think about. How come you never see a headline like 'Psychic Wins Lottery!'? - Jay Leno
 
See "Dir Function" in the VBA help file. That will give an option to confirm the image file exists or not

________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
Similar to Zameer's approach
Code:
   Dim strImagePathAndFile As String
   Dim objFileSystem As Object
   'strImagePathAndFile =  
   Set objFileSystem =    
   CreateObject("Scripting.FileSystemObject")
   If objFileSystem.FileExists(strImagePathAndFile) Then
      mImageControl.Picture = strImagePathAndFile
   Else
      mImageControl.Picture = ""
      'msgbox "No Picture"
   end if
 
In VBE - Tools | Options - general tab - > use "Break on unhandled errors" (I think you've got "Break on all errors"?)

Roy-Vidar
 
Roy-Vidar

Thanks, looked in VBE tools|options as you suggested and you were right. The "break on all errors" was selected. Switched to "break on unhandled errors" and the problem is gone.

I would have probably never thought to have looked there, so I give you a star for saving me the troubles I would have had to deal with otherwise.

ZmrAbdulla and MajP

Thanks for the other suggestions. May come in handy. At least I see there are alternatives.

-- Fast Learner, I Think

Here's something to think about. How come you never see a headline like 'Psychic Wins Lottery!'? - Jay Leno
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top