For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > April 2006 > On error goto problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author On error goto problem
HDI

2006-04-28, 7:56 am

Hi,

I've got following code in access:

For each ....

on error goto errhand


errhand:
...

next

When the first error occures he handles errhand, correct.
when the second error occures access gives a global error and doen's
handle errhand.

Thx

J French

2006-04-28, 7:56 am

On 28 Apr 2006 05:18:57 -0700, "HDI" <hdinf@hotmail.com> wrote:

>Hi,
>
>I've got following code in access:
>
>For each ....
>
> on error goto errhand
>
>
> errhand:
> ...
>
>next
>
>When the first error occures he handles errhand, correct.
>when the second error occures access gives a global error and doen's
>handle errhand.


Look into 'Resume'

Research it right down to its bowels

Maybe use :-
On Error Resume Next

Test it out, call a Sub that divides 1 by 0 and watch what happens


Ken Halter

2006-04-28, 6:56 pm

"HDI" <hdinf@hotmail.com> wrote in message
news:1146226737.328762.118170@y43g2000cwc.googlegroups.com...
> Hi,
>
> I've got following code in access:
>
> For each ....
>
> on error goto errhand
>
>
> errhand:
> ...
>
> next
>
> When the first error occures he handles errhand, correct.
> when the second error occures access gives a global error and doen's
> handle errhand.
>
> Thx


The On Error label should only have to be set once... not in a loop like
you're doing. If you want the functionality it seems you're looking for, do
something like...
'==========
Private Sub Command1_Click()
Dim c As Control

On Error Resume Next

For Each c In Controls
'this'll raise an error for any control on the form
'that doesn't expose a 'Text' property
Debug.Print c.Text

'Test the error to see if it's non-zero
If Err.Number <> 0 Then
'An error was raised, take action
Debug.Print c.Name & " doesn't expose a 'Text' property"
End If

'Clear the error object so it's ready for use later
Err.Clear
Next

End Sub
'==========


--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com