By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Can't trap error in called routine

P: n/a
I'm using the following routine to call UpdateDiary() - below:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Error

Call UpdateDiary(Me!TenantCounter, "sfTenantDetailsOther")

Exit Sub
Form_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure Form_BeforeUpdate in Line " & Erl & "."
Exit Sub
End Sub

Function UpdateDiary(vTenantCounter As Long, strSource As String) As
Boolean
On Error GoTo ErrorUpdateDiary
'Called from Form Before update
Dim db As Database, rsEvents As Recordset
Dim sf As Control, ctrl As Control
Dim strFld As String, vNewDate As Variant, vOldDate As Variant

Set db = CurrentDb

Set sf = Forms!fTenantDetails(strSource)
Set rsEvents = db.OpenRecordset("SELECT * FROM tDiaryEventTypes
WHERE TypeID < 20")
With rsEvents
Do Until .EOF
strFld = !LinkedField
vNewDate = sf.Form(strFld)
vOldDate = sf.Form(strFld).OldValue
vNewDate <Nz(vOldDate, 0) Then
etc etc etc
NextEvent:
.MoveNext
Loop
End With

UpdateDiary = True

CloseFunction:
On Error Resume Next
DoCmd.Hourglass False
Exit Function

ErrorUpdateDiary:
If Err = 438 Then
GoTo NextEvent 'Can only read 'OldValue' if control is on form
Else
MsgBox Error$ & " " & Err
End If
Resume CloseFunction
End Function

rsEvents lists a number of fields, which can be on any one of a number of
subforms.
The Field and Control Names are identical.
It works fine provided the field is found. But if the field doesn't exist on
the subform being checked, the UpdateDiary routine fails and returns to the
calling sub error code.
Can anyone tell me why doesn't it go to the error code in UpdateDiary?

--
Bob Darlington
Brisbane
Feb 20 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Forgot to mention the error generated from the calling routine is 2465 -
"Can't find field ...."

--
Bob Darlington
Brisbane
"Bob Darlington" <bo*@dpcmanAX.com.auwrote in message
news:45**********************@news.optusnet.com.au ...
I'm using the following routine to call UpdateDiary() - below:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Error

Call UpdateDiary(Me!TenantCounter, "sfTenantDetailsOther")

Exit Sub
Form_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure Form_BeforeUpdate in Line " & Erl & "."
Exit Sub
End Sub

Function UpdateDiary(vTenantCounter As Long, strSource As String) As
Boolean
On Error GoTo ErrorUpdateDiary
'Called from Form Before update
Dim db As Database, rsEvents As Recordset
Dim sf As Control, ctrl As Control
Dim strFld As String, vNewDate As Variant, vOldDate As Variant

Set db = CurrentDb

Set sf = Forms!fTenantDetails(strSource)
Set rsEvents = db.OpenRecordset("SELECT * FROM tDiaryEventTypes
WHERE TypeID < 20")
With rsEvents
Do Until .EOF
strFld = !LinkedField
vNewDate = sf.Form(strFld)
vOldDate = sf.Form(strFld).OldValue
vNewDate <Nz(vOldDate, 0) Then
etc etc etc
NextEvent:
.MoveNext
Loop
End With

UpdateDiary = True

CloseFunction:
On Error Resume Next
DoCmd.Hourglass False
Exit Function

ErrorUpdateDiary:
If Err = 438 Then
GoTo NextEvent 'Can only read 'OldValue' if control is on form
Else
MsgBox Error$ & " " & Err
End If
Resume CloseFunction
End Function

rsEvents lists a number of fields, which can be on any one of a number of
subforms.
The Field and Control Names are identical.
It works fine provided the field is found. But if the field doesn't exist
on the subform being checked, the UpdateDiary routine fails and returns to
the calling sub error code.
Can anyone tell me why doesn't it go to the error code in UpdateDiary?

--
Bob Darlington
Brisbane

Feb 20 '07 #2

P: n/a
On Feb 20, 1:41 am, "Bob Darlington" <b...@dpcmanAX.com.auwrote:
Forgot to mention the error generated from the calling routine is 2465 -
"Can't find field ...."

--
Bob Darlington
Brisbane"Bob Darlington" <b...@dpcmanAX.com.auwrote in message

news:45**********************@news.optusnet.com.au ...
I'm using the following routine to call UpdateDiary() - below:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Error
Call UpdateDiary(Me!TenantCounter, "sfTenantDetailsOther")
Exit Sub
Form_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure Form_BeforeUpdate in Line " & Erl & "."
Exit Sub
End Sub
Function UpdateDiary(vTenantCounter As Long, strSource As String) As
Boolean
On Error GoTo ErrorUpdateDiary
'Called from Form Before update
Dim db As Database, rsEvents As Recordset
Dim sf As Control, ctrl As Control
Dim strFld As String, vNewDate As Variant, vOldDate As Variant
Set db = CurrentDb
Set sf = Forms!fTenantDetails(strSource)
Set rsEvents = db.OpenRecordset("SELECT * FROM tDiaryEventTypes
WHERE TypeID < 20")
With rsEvents
Do Until .EOF
strFld = !LinkedField
vNewDate = sf.Form(strFld)
vOldDate = sf.Form(strFld).OldValue
vNewDate <Nz(vOldDate, 0) Then
etc etc etc
NextEvent:
.MoveNext
Loop
End With
UpdateDiary = True
CloseFunction:
On Error Resume Next
DoCmd.Hourglass False
Exit Function
ErrorUpdateDiary:
If Err = 438 Then
GoTo NextEvent 'Can only read 'OldValue' if control is on form
Else
MsgBox Error$ & " " & Err
End If
Resume CloseFunction
End Function
rsEvents lists a number of fields, which can be on any one of a number of
subforms.
The Field and Control Names are identical.
It works fine provided the field is found. But if the field doesn't exist
on the subform being checked, the UpdateDiary routine fails and returns to
the calling sub error code.
Can anyone tell me why doesn't it go to the error code in UpdateDiary?
--
Bob Darlington
Brisbane

In the code window, under Tools, Options - "General" tab, do you have
have 'Break on Unhandled Errors' selected in the Error Trapping
section? If not, you'll need to select this in order for your error
handler to work correctly.

Bruce

Feb 20 '07 #3

P: n/a
On Feb 20, 2:41 am, "Bob Darlington" <b...@dpcmanAX.com.auwrote:
Forgot to mention the error generated from the calling routine is 2465 -
"Can't find field ...."

--
Bob Darlington
Brisbane"Bob Darlington" <b...@dpcmanAX.com.auwrote in message

news:45**********************@news.optusnet.com.au ...
I'm using the following routine to call UpdateDiary() - below:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Error
Call UpdateDiary(Me!TenantCounter, "sfTenantDetailsOther")
Exit Sub
Form_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure Form_BeforeUpdate in Line " & Erl & "."
Exit Sub
End Sub
Function UpdateDiary(vTenantCounter As Long, strSource As String) As
Boolean
On Error GoTo ErrorUpdateDiary
'Called from Form Before update
Dim db As Database, rsEvents As Recordset
Dim sf As Control, ctrl As Control
Dim strFld As String, vNewDate As Variant, vOldDate As Variant
Set db = CurrentDb
Set sf = Forms!fTenantDetails(strSource)
Set rsEvents = db.OpenRecordset("SELECT * FROM tDiaryEventTypes
WHERE TypeID < 20")
With rsEvents
Do Until .EOF
strFld = !LinkedField
vNewDate = sf.Form(strFld)
vOldDate = sf.Form(strFld).OldValue
vNewDate <Nz(vOldDate, 0) Then
etc etc etc
NextEvent:
.MoveNext
Loop
End With
UpdateDiary = True
CloseFunction:
On Error Resume Next
DoCmd.Hourglass False
Exit Function
ErrorUpdateDiary:
If Err = 438 Then
GoTo NextEvent 'Can only read 'OldValue' if control is on form
Else
MsgBox Error$ & " " & Err
End If
Resume CloseFunction
End Function
rsEvents lists a number of fields, which can be on any one of a number of
subforms.
The Field and Control Names are identical.
It works fine provided the field is found. But if the field doesn't exist
on the subform being checked, the UpdateDiary routine fails and returns to
the calling sub error code.
Can anyone tell me why doesn't it go to the error code in UpdateDiary?
--
Bob Darlington
Brisbane

If you expect the 2465 error to occur because a control may or may not
be there, it would be better to revise your code to account for it.
Include a check to see if the error is 2465, then either Resume Next
or Resume something else. Also, I believe the only time an error event
completes itself is when a Resume, Exit or End statement is
encountered. I'm not sure using the Goto in your handler resets the
error event. You should use Resume NextEvent. If you encounter an
error before the first is dealt with, I think the proceedure stops
entirely.

Feb 20 '07 #4

P: n/a
Thanks for the reply Bruce. I did have that check box checked.

--
Bob Darlington
Brisbane
"Bruce" <de***************@gmail.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
On Feb 20, 1:41 am, "Bob Darlington" <b...@dpcmanAX.com.auwrote:
>Forgot to mention the error generated from the calling routine is 2465 -
"Can't find field ...."

--
Bob Darlington
Brisbane"Bob Darlington" <b...@dpcmanAX.com.auwrote in message

news:45**********************@news.optusnet.com.a u...
I'm using the following routine to call UpdateDiary() - below:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Error
Call UpdateDiary(Me!TenantCounter, "sfTenantDetailsOther")
Exit Sub
Form_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure Form_BeforeUpdate in Line " & Erl & "."
Exit Sub
End Sub
Function UpdateDiary(vTenantCounter As Long, strSource As String) As
Boolean
On Error GoTo ErrorUpdateDiary
'Called from Form Before update
Dim db As Database, rsEvents As Recordset
Dim sf As Control, ctrl As Control
Dim strFld As String, vNewDate As Variant, vOldDate As Variant
Set db = CurrentDb
Set sf = Forms!fTenantDetails(strSource)
Set rsEvents = db.OpenRecordset("SELECT * FROM tDiaryEventTypes
WHERE TypeID < 20")
With rsEvents
Do Until .EOF
strFld = !LinkedField
vNewDate = sf.Form(strFld)
vOldDate = sf.Form(strFld).OldValue
vNewDate <Nz(vOldDate, 0) Then
etc etc etc
NextEvent:
.MoveNext
Loop
End With
UpdateDiary = True
CloseFunction:
On Error Resume Next
DoCmd.Hourglass False
Exit Function
ErrorUpdateDiary:
If Err = 438 Then
GoTo NextEvent 'Can only read 'OldValue' if control is on form
Else
MsgBox Error$ & " " & Err
End If
Resume CloseFunction
End Function
rsEvents lists a number of fields, which can be on any one of a number
of
subforms.
The Field and Control Names are identical.
It works fine provided the field is found. But if the field doesn't
exist
on the subform being checked, the UpdateDiary routine fails and returns
to
the calling sub error code.
Can anyone tell me why doesn't it go to the error code in UpdateDiary?
--
Bob Darlington
Brisbane


In the code window, under Tools, Options - "General" tab, do you have
have 'Break on Unhandled Errors' selected in the Error Trapping
section? If not, you'll need to select this in order for your error
handler to work correctly.

Bruce

Feb 21 '07 #5

P: n/a


--
Bob Darlington
Brisbane
"storrboy" <st******@sympatico.cawrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
On Feb 20, 2:41 am, "Bob Darlington" <b...@dpcmanAX.com.auwrote:
>Forgot to mention the error generated from the calling routine is 2465 -
"Can't find field ...."

--
Bob Darlington
Brisbane"Bob Darlington" <b...@dpcmanAX.com.auwrote in message

news:45**********************@news.optusnet.com.a u...
I'm using the following routine to call UpdateDiary() - below:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Error
Call UpdateDiary(Me!TenantCounter, "sfTenantDetailsOther")
Exit Sub
Form_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure Form_BeforeUpdate in Line " & Erl & "."
Exit Sub
End Sub
Function UpdateDiary(vTenantCounter As Long, strSource As String) As
Boolean
On Error GoTo ErrorUpdateDiary
'Called from Form Before update
Dim db As Database, rsEvents As Recordset
Dim sf As Control, ctrl As Control
Dim strFld As String, vNewDate As Variant, vOldDate As Variant
Set db = CurrentDb
Set sf = Forms!fTenantDetails(strSource)
Set rsEvents = db.OpenRecordset("SELECT * FROM tDiaryEventTypes
WHERE TypeID < 20")
With rsEvents
Do Until .EOF
strFld = !LinkedField
vNewDate = sf.Form(strFld)
vOldDate = sf.Form(strFld).OldValue
vNewDate <Nz(vOldDate, 0) Then
etc etc etc
NextEvent:
.MoveNext
Loop
End With
UpdateDiary = True
CloseFunction:
On Error Resume Next
DoCmd.Hourglass False
Exit Function
ErrorUpdateDiary:
If Err = 438 Then
GoTo NextEvent 'Can only read 'OldValue' if control is on form
Else
MsgBox Error$ & " " & Err
End If
Resume CloseFunction
End Function
rsEvents lists a number of fields, which can be on any one of a number
of
subforms.
The Field and Control Names are identical.
It works fine provided the field is found. But if the field doesn't
exist
on the subform being checked, the UpdateDiary routine fails and returns
to
the calling sub error code.
Can anyone tell me why doesn't it go to the error code in UpdateDiary?
--
Bob Darlington
Brisbane


If you expect the 2465 error to occur because a control may or may not
be there, it would be better to revise your code to account for it.
Include a check to see if the error is 2465, then either Resume Next
or Resume something else. Also, I believe the only time an error event
completes itself is when a Resume, Exit or End statement is
encountered. I'm not sure using the Goto in your handler resets the
error event. You should use Resume NextEvent. If you encounter an
error before the first is dealt with, I think the proceedure stops
entirely.
Thanks for the reply.
The problem is how to check for the error.
At present, if the field is not found, it jumps back to the calling routine,
bypassing the error code in the called routine.
Feb 21 '07 #6

P: n/a
On Feb 20, 8:20 pm, "Bob Darlington" <b...@dpcmanAX.com.auwrote:
--
Bob Darlington
Brisbane"storrboy" <storr...@sympatico.cawrote in message

news:11**********************@l53g2000cwa.googlegr oups.com...
On Feb 20, 2:41 am, "Bob Darlington" <b...@dpcmanAX.com.auwrote:
Forgot to mention the error generated from the calling routine is 2465 -
"Can't find field ...."
--
Bob Darlington
Brisbane"Bob Darlington" <b...@dpcmanAX.com.auwrote in message
>news:45**********************@news.optusnet.com.a u...
I'm using the following routine to call UpdateDiary() - below:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Error
Call UpdateDiary(Me!TenantCounter, "sfTenantDetailsOther")
Exit Sub
Form_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure Form_BeforeUpdate in Line " & Erl & "."
Exit Sub
End Sub
Function UpdateDiary(vTenantCounter As Long, strSource As String) As
Boolean
On Error GoTo ErrorUpdateDiary
'Called from Form Before update
Dim db As Database, rsEvents As Recordset
Dim sf As Control, ctrl As Control
Dim strFld As String, vNewDate As Variant, vOldDate As Variant
Set db = CurrentDb
Set sf = Forms!fTenantDetails(strSource)
Set rsEvents = db.OpenRecordset("SELECT * FROM tDiaryEventTypes
WHERE TypeID < 20")
With rsEvents
Do Until .EOF
strFld = !LinkedField
vNewDate = sf.Form(strFld)
vOldDate = sf.Form(strFld).OldValue
vNewDate <Nz(vOldDate, 0) Then
etc etc etc
NextEvent:
.MoveNext
Loop
End With
UpdateDiary = True
CloseFunction:
On Error Resume Next
DoCmd.Hourglass False
Exit Function
ErrorUpdateDiary:
If Err = 438 Then
GoTo NextEvent 'Can only read 'OldValue' if control is on form
Else
MsgBox Error$ & " " & Err
End If
Resume CloseFunction
End Function
rsEvents lists a number of fields, which can be on any one of a number
of
subforms.
The Field and Control Names are identical.
It works fine provided the field is found. But if the field doesn't
exist
on the subform being checked, the UpdateDiary routine fails and returns
to
the calling sub error code.
Can anyone tell me why doesn't it go to the error code in UpdateDiary?
--
Bob Darlington
Brisbane
If you expect the 2465 error to occur because a control may or may not
be there, it would be better to revise your code to account for it.
Include a check to see if the error is 2465, then either Resume Next
or Resume something else. Also, I believe the only time an error event
completes itself is when a Resume, Exit or End statement is
encountered. I'm not sure using the Goto in your handler resets the
error event. You should use Resume NextEvent. If you encounter an
error before the first is dealt with, I think the proceedure stops
entirely.

Thanks for the reply.
The problem is how to check for the error.
At present, if the field is not found, it jumps back to the calling routine,
bypassing the error code in the called routine.

And I think that's because your not fully handling the error. It
should probably look something like this instead...

ErrorUpdateDiary:
Select Case Err.Number
Case 438, 2465 'Can only read 'OldValue' if control
is on form
Resume Next Event
Case Else
MsgBox Err.Number & " - " & Err.Description
Resume CloseFunction
End Select
End Function

Feb 21 '07 #7

P: n/a

"storrboy" <st******@sympatico.cawrote in message
news:11********************@s48g2000cws.googlegrou ps.com...
On Feb 20, 8:20 pm, "Bob Darlington" <b...@dpcmanAX.com.auwrote:
>--
Bob Darlington
Brisbane"storrboy" <storr...@sympatico.cawrote in message

news:11**********************@l53g2000cwa.googleg roups.com...
On Feb 20, 2:41 am, "Bob Darlington" <b...@dpcmanAX.com.auwrote:
Forgot to mention the error generated from the calling routine is
2465 -
"Can't find field ...."
>--
Bob Darlington
Brisbane"Bob Darlington" <b...@dpcmanAX.com.auwrote in message
>>news:45**********************@news.optusnet.com. au...
I'm using the following routine to call UpdateDiary() - below:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Error
Call UpdateDiary(Me!TenantCounter, "sfTenantDetailsOther")
Exit Sub
Form_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") "
_
& "in procedure Form_BeforeUpdate in Line " & Erl &
"."
Exit Sub
End Sub
Function UpdateDiary(vTenantCounter As Long, strSource As String)
As
Boolean
On Error GoTo ErrorUpdateDiary
'Called from Form Before update
Dim db As Database, rsEvents As Recordset
Dim sf As Control, ctrl As Control
Dim strFld As String, vNewDate As Variant, vOldDate As
Variant
Set db = CurrentDb
Set sf = Forms!fTenantDetails(strSource)
Set rsEvents = db.OpenRecordset("SELECT * FROM
tDiaryEventTypes
WHERE TypeID < 20")
With rsEvents
Do Until .EOF
strFld = !LinkedField
vNewDate = sf.Form(strFld)
vOldDate = sf.Form(strFld).OldValue
vNewDate <Nz(vOldDate, 0) Then
etc etc etc
NextEvent:
.MoveNext
Loop
End With
UpdateDiary = True
CloseFunction:
On Error Resume Next
DoCmd.Hourglass False
Exit Function
ErrorUpdateDiary:
If Err = 438 Then
GoTo NextEvent 'Can only read 'OldValue' if control is on
form
Else
MsgBox Error$ & " " & Err
End If
Resume CloseFunction
End Function
rsEvents lists a number of fields, which can be on any one of a
number
of
subforms.
The Field and Control Names are identical.
It works fine provided the field is found. But if the field doesn't
exist
on the subform being checked, the UpdateDiary routine fails and
returns
to
the calling sub error code.
Can anyone tell me why doesn't it go to the error code in
UpdateDiary?
--
Bob Darlington
Brisbane
If you expect the 2465 error to occur because a control may or may not
be there, it would be better to revise your code to account for it.
Include a check to see if the error is 2465, then either Resume Next
or Resume something else. Also, I believe the only time an error event
completes itself is when a Resume, Exit or End statement is
encountered. I'm not sure using the Goto in your handler resets the
error event. You should use Resume NextEvent. If you encounter an
error before the first is dealt with, I think the proceedure stops
entirely.

Thanks for the reply.
The problem is how to check for the error.
At present, if the field is not found, it jumps back to the calling
routine,
bypassing the error code in the called routine.


And I think that's because your not fully handling the error. It
should probably look something like this instead...

ErrorUpdateDiary:
Select Case Err.Number
Case 438, 2465 'Can only read 'OldValue' if control
is on form
Resume Next Event
Case Else
MsgBox Err.Number & " - " & Err.Description
Resume CloseFunction
End Select
End Function
Thanks for the reply, and sorry I'm late responding.
The problem was that the error wouldn't trigger 'ErrorUpdateDiary'. It just
went back to the calling routine.
But your earlier response gave me a clue and I've since used:
On Error GoTo ErrorFieldNotFound
vFld = sf(strFld)
vNewDate = sf(strFld)
vOldDate = sf(strFld).OldValue
On Error GoTo ErrorUpdateDiary

ErrorFieldNotFound:
Err.Clear
Resume NextEvent

and it works OK.
But I still can't figure why the jump to the calling routine occurred. Every
prior error should have been dealt with by the called routine. And how did
the calling routine get details of the error from the called routine?

Anyhow, thanks for your help.

--
Bob Darlington
Brisbane
Feb 27 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.