[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

VB/VBA Puzzle

Hi guys.

I have one vba routine that calls another.  When the other routine is called a check is run and, if this check fails (ie is FALSE) I want it to halt running code altogether.  At the moment all I can get it to do is to stop the other routine with 'Exit Sub', but the code then returns to the original calling procedure and continues to run.

How would I go about doing this properly?

Thanks in advance.
Matt
0
2toria
Asked:
2toria
1 Solution
 
VTKeganCommented:
If the second routine is returning false, then in the first routine which calls the check you should use something like

If RunCheckRoutine <> False Then
  'Keep running your code

Else
  Exit Sub

End If
0
 
2toriaAuthor Commented:
Great idea - I managed to use this kind of thinking to work around the problem.  Cheers.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Note also that you must use Functions in order to "return" a value:

Function SomeFunction() As Boolean
  '/code here
  SomeFunction = False
End Function

Then call it like this:

If SomeFunction = True Then
  '/run your other code here
End If
0
 
omgangCommented:
Expanding on what VTKegan said, you'll want to change the second routine from a Sub to a Function and set a Function return value of Boolean

So instead of

Private Sub SecondRoutine()

change it to

Private Function SecondRoutine() As Boolean


    'here's where the check is performed
    If Check = False Then
        SecondRoutine = False
        Exit Function
    Else
        SecondRouting = True
    End If

End Function


Then you call it from you first routine exactly like VTKegan suggests

If SecondRoutine <> False Then
    etc.


OM Gang
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now