Resume Without Error Issue

AbbottF

Registered User.
Local time
Today, 09:47
Joined
Jan 22, 2013
Messages
25
I'm getting aa strange issue with a clas module. A function (see below) creates some error that is not passed to the error handler. Instead, it falls thru from the exit to the error handler & goes into an endless loop of blank dialog followed by a "Resume without error" dialog. It even happens when I remove the Event logic in the middle. It even happens with Err.Clear called. I've compiled the db with no errors ????

Code:
Private Function ProcessCurrentContactEvents(contactID As Integer, events As Recordset) As Integer
 
    Dim Money As Currency
    Dim family As String
    Dim adult As String
    Dim note As String
    Dim theDate As Date
    Dim catID As Integer
    Dim catTypeID As Integer
    Dim returnCount As Integer
    returnCount = 0
 
    On Error GoTo Err_ProcessCurrentContactEvents
 
    ' 2013 Event
    If events![2013YTD] > 0 Then
        family = events![2013FamilyEventName]
        adult = events![2013AdultEventName]
        Money = events![2013YTD]
        theDate = CDate("2013-01-01")
        returnCount = returnCount + AddEvent(ContactID, family, adult, Money, theDate)
    End If
 
    ' 2012 Event
    If events![2012YTD] > 0 Then
        family = events![2012FamilyEventName]
        adult = events![2012AdultEventName]
        Money = events![2012YTD]
        theDate = CDate("2012-01-01")
        returnCount = returnCount + AddEvent(ContactID, family, adult, Money, theDate)
    End If
 
    ' 2011 Event
    If events![2011YTD] > 0 Then
        family = events![2011FamilyEventName]
        adult = events![2011AdultEventName]
        Money = events![2011YTD]
        theDate = CDate("2011-01-01")
        returnCount = returnCount + AddEvent(ContactID, family, adult, Money, theDate)
    End If
 
    ' 2010 Event
    If events![2010YTD] > 0 Then
        family = events![2010FamilyEventName]
        adult = events![2010AdultEventName]
        Money = events![2010YTD]
        theDate = CDate("2010-01-01")
        returnCount = returnCount + AddEvent(ContactID, family, adult, Money, theDate)
    End If
 
    ' 2009 Event
    If events![2009YTD] > 0 Then
        family = events![2009FamilyEventName]
        adult = events![2009AdultEventName]
        Money = events![2009YTD]
        theDate = CDate("2009-01-01")
        returnCount = returnCount + AddEvent(ContactID, family, adult, Money, theDate)
    End If
 
    ' 2008 Event
    If events![2008YTD] > 0 Then
        family = events![2008FamilyEventName]
        adult = events![2008AdultEventName]
        Money = events![2008YTD]
        theDate = CDate("2008-01-01")
        returnCount = returnCount + AddEvent(ContactID, family, adult, Money, theDate)
    End If
 
Exit_ProcessCurrentContactEvents:
    Err.Clear
    ProcessCurrentContactEvents = returnCount
 
Err_ProcessCurrentContactEvents:
    MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
    Resume Exit_ProcessCurrentContactEvents
 
the bit at the bottom.

you need an EXIT SUB statement in the exit block, otherwise the code drops into the error handler, which is why you get the resume without error message.


Code:
Exit_ProcessCurrentContactEvents:
Err.Clear
ProcessCurrentContactEvents = returnCount
 
[COLOR=red]exit sub[/COLOR]
[COLOR=red]***********[/COLOR]
 
Err_ProcessCurrentContactEvents:
MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
Resume Exit_ProcessCurrentContactEvents
 
I don't understand, since it's a Function and NOT a Sub Exit Sub is invalid and rejected by the compiler. The line below is supposed to cause the exit while setting the proper return value. I use it throughout the project.

ProcessCurrentContactEvents = returnCount
 
exit function then, rather than exit sub. just change it.

the point is, you need the code to stop - not drop into the error handler block.
 
Thanks. But End Function is an invalid construct. VBA throw a compiler error. Anyway, I just removed the error testing totally, since this is a one shot conversion.
 
But next time you code an error handler for a function, you might want to follow Dave's recipe. You need to exit before the error handler, or else it will be executed every time.

BTW: If your code displayed in #1 is executing then you have accomplished a miracle - having a function run without End Function..
 
I'm getting aa strange issue with a clas module.

What you have shown looks like a function in a standard module. Why do you think it is a class module?
 
It's in a class module. I meant there is no exit function construct in VBA. the end function was not copied into the message. Everything is working now, with the error code commented out. It's part of a data conversion fom a very old access membership module to one that supports the needs of the group much better.Thanks.
 

Users who are viewing this thread

Back
Top Bottom