Exitting a Command Button's Sub Routine

lewando_bria

BoRiS
Local time
, 20:12
Joined
Jun 18, 2002
Messages
29
Hey there...I have a form with several command buttons to perform various record functions...i am trying to structure a Public Sub Routine that checks the form's controls for null values and exits the command button's routine if there are any null values....I'm just wondering if this is possible and how I would go about doing it.,...thanks!!!
 
use "Exit Sub" when you conditions to continue are not true.

Example:

If ISNULL(Me.[ControlName])=True then Exit Sub
 
Thanks Travis, but my question was a little bit understood (or I was too vague)...I want to create a Public Sub Routine that performs only the checking of controls for Null Values, there are several different Command Buttons that would call this function....I am checking to see if there is a line of code I could insert within the Public Sub Routine to exit the Command Button's routine...in other words, how do I exit an onclick event from a sub routine that is not the onClick event...i think that made sense of it....thanks!
 
...in other words, how do I exit an onclick event from a sub routine that is not the onClick event

You don't Exit a procedure from another procedure. What you do is create your checking procedure as a Function that returns a boolean, and you check to see if the return is false/true and you make a choice to continue from there.


Sub MyTest_Click()

If MyCheck(Me.[MyControl])=False Exit Sub

End Sub

Function MyCheck(ctrMyTest as Control) as Boolean

If IsNull(ctrMyTest) Then
MyCheck=False
Else
MyCheck=True
End If

End Function
 

Users who are viewing this thread

Back
Top Bottom