PDA

View Full Version : Solved: Error error



ben.oates
04-16-2008, 04:33 AM
Hi all,

I have been stepping into the code below:

'Return true if it is found in the table
'This is only a superficial check. This does not mean that the whole order has been delivered.
Public Function checkDelivery(myPO As String) As Boolean
Dim rs As DAO.Recordset
On Error GoTo ErrHandler

Set rs = CurrentDb.OpenRecordset("Goods Inward-Outward", dbOpenSnapshot)
checkDelivery = False

If myPO <> "" Then
rs.FindFirst "[Purchasing PO] ='" & myPO & "'"
If rs.NoMatch Then
'Will throw exception 13 if myPO is a string
rs.FindFirst "[Standard PO] =" & CLng(myPO)
If rs.NoMatch Then
'checkDelivery = False
rs.Close
Exit Function
End If
End If
End If

checkDelivery = True
rs.Close

Exit Function

ErrHandler:
Select Case Err.Number
Case 13
'There has been a problem converting to CLng
'This is not serious and would imply that the string would not be found in the check anyway
checkDelivery = False
rs.Close
Exit Function
Case Else
'This is an unknown error - report it
raiseLog "<p>An error has occured in checkDelivery. The error number is: " & _
Err.Number & " and the description is: </p><p>" & Err.Description & _
vbCrLf & "</p><p>This is very important. This may have resulted in " & _
"the inaccurate reclassification of an ARSR.</p>", High, "Error Occured"
Resume Next
End Select
rs.Close
End Function

When exception 13 is thrown trying to convert to Long - as expected in certain instances - it goes to ErrHandler as expected, but as soon as it hits the Select Case Err.Number changes from 13 to 0. I can't work it out! Any suggestions? I've been stepping through it and can't see that I've missed anything. Very confused. :think:

Any help, as always, is greatly appreciated.

OTWarrior
04-16-2008, 05:28 AM
Have you tried saving the err.number into a value, and then testing it in the error handler?

dim errNum as integer
'etc etc

errHandler:
errNum = err.number

Select Case errNum
'etc etc

ben.oates
04-16-2008, 09:31 AM
Hi OTWarrior,

That has the same effect. As soon as I set errNum = Err.Number it changes to 0 and errNum and errDescription (my variables) are set to useless values.

I don't understand, this hasn't happened before. Any ideas?

ben.oates
04-16-2008, 09:48 AM
Hmm, it appears it was one of those wonderful "features" where you have to save, close and start again. Problem solved.