Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about called and calling procedures

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi

On my Sub_Exit procedure I call a Sub_Myprocedure.
What should I code in my Sub_Myprocedure in order to not return to my Sub_Exit after the certain condition's hit.

E.g.

Sub_Exit

If something
call Sub_Myprocedure
Else
docmd.close
End if

Run sql

End sub


Sub_Myprocedure

If something
'here i want to exit from Sub_Myprocedure as well as from Sub_Exit so that Run sql statement in the Sub_Exit wouldn't run
else
do something and return to SUb_Exit
end if
end sub


Well, it probably looks silly
But please, help a novice to figure out the basics

Thanks
 
It's all down to the way you structure your code..
If I understrand correctly move Run sql to the second sub
ie.

Sub_Exit

If something
call Sub_Myprocedure
Else
docmd.close
End if

End sub


Sub_Myprocedure

If something
'here i want to exit from Sub_Myprocedure as well as from Sub_Exit so that Run sql statement in the Sub_Exit wouldn't run
else
do something and return to SUb_Exit

Run sql

end if
end sub

That will cause it to run only where you want it to..

There are two ways to write error-free programs; only the third one works.
 
Surely you should also have Run sql contained within the first else statement?

Since if you meet the condition for the if statement you will perform another check(in Sub_MyProcedure) to determine whether you want to Run sql but if you don't meet the condition then you will always want to Run sql.

So it ends up looking like this:

Sub_Exit

If something Then
call Sub_Myprocedure
Else
docmd.close
Run sql
End if
End sub

Sub_Myprocedure

If something
'here i want to exit from Sub_Myprocedure as well as from Sub_Exit so that Run sql statement in the Sub_Exit wouldn't run

else
do something
Run sql
return to SUb_Exit
end if
end sub

Cheers,

Pete
 
Hi!

Another possibility is to change the Sub_Myprocedure into a boolean function which will return false if your condition to not run is met. Then you can check what value was returned to determine if the sql needs to be run. This way you can leave the Run sql in the exit procedure if you feel that is the logical place for it.

Note: GHolden's solution is certainly simpler and should be used unless it affects the readability of the code.

hth
Jeff Bridgham
bridgham@purdue.edu
 
THank you all for the help

I end up using boolean function as jebry mentioned, since the it is the best way to ease the code readability.

Great people, great ideas, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top