pob wrote:
>>From a form I have some code that calls 4 modules
frmMain
1 mod
2 mod
3 mod
4 mod
2 questions
1-If an error occurs in mod 1 the program exits mod1 and goes back to
frmMain where it continues with mod 2, mod3, and mod 4.
How do I get the program to stop and not continue with any modules in
frmMain if an error occurred in any of the the called modules ?
First of all, your terminology is incorrect. You're not calling
modules, you're calling procedures (functions or subs). These
procedures may be stored in different standard or class (form or report)
modules.
Getting back to your first question, there are a couple of ways to do
this. A combination could be done.
If what you call "1 mod", etc are *functions*, you could have functions
as booleans with a properly completed function returning a true and the
error handling in each function causing the function to return a false.
Function Mod1() as Boolean
blah, blah
Exit_Proc:
Exit Function
Err_Proc:
Select case err.number
case else
Mod1 = false
resume exit_Proc
End Select
End Function
Sub sMain()
dim booOk as boolean
booOk = true
booOk = Mod1 'returns false if error
if booOk = True then booOk = Mod2
etc, etc.
The other way is to pass the booOK to the Mod1 subs so that the Mod1
procedure looks somethig like
Sub Mod1(ByRef boo1 as boolean)
'boo1 passed as true, changed to false on error
blah, blah
Exit_Proc:
Exit Sub
Err_Proc:
Select case err.number
case else
boo1 = false
resume exit_Proc
End Select
End Sub
The main procedure would look like:
Sub sMain()
dim booOk as boolean
booOk = true
Mod1(booOk)
if booOk = True then Mod2(booOk)
etc, etc.
2-I have error handling within each module, can someone provide me with
a link or an example where I can simplify my error handling into a
separate module ?
Again, the proper question is "I have error handling within each
PROCEDURE, can someone provide me with a link or an example where I can
simplify my error handling into a separate PROCEDURE?"
I generally don't recommend this approach but that's my approach. I use
some error handling this way, but only for displaying database errors
from Oracle when I'm using Access as an Oracle FE.
But that's my opinion. There are other far more experienced developers
on this group who will disagree.
--
Tim
http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me