Share via

vba to stop all macros

Anonymous
2014-04-17T00:12:17+00:00

I have a macro that does steps 1-3, step 4 is RunCode GetStuffAndDoStuff()

Steps 5 and 6 are more macro commands.

If there is an error in step 4, the part that is VBA code, on error exit function just continues the flow with steps 5 and 6. 

How do I stop all macros if step 4 errors so that steps 5 and 6 don't execute?

Something like on error DoCmd.StopAllMacros

Thanks in advance.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

11 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points MVP Volunteer Moderator
    2014-04-17T05:53:45+00:00

    The instruction

    End

    will end all code execution and reset all variables.

    2 people found this answer helpful.
    0 comments No comments
  2. HansV 462.6K Reputation points MVP Volunteer Moderator
    2014-04-17T21:42:13+00:00

    Try this:

    Public Function Lib_Forms() As Boolean

        Dim Filename As String

        Dim DestName As String

        Dim OrigPath As String

        Dim OrigFile As String

        Dim DestFile As String

        On Local Error GoTo Out

        OrigPath = "L:\legalper\lib\forms"

        OrigFile = Form_DA.LibForm.Text

        If Forms!DA!DA = 2 Then

            DestFile = "merge_li.docx"

        ElseIf Forms!DA!DA = 1 Then

            DestFile = "merge_li.frm"

        End If

        DestName = Tmppath & DestFile

        Filename = OrigPath & OrigFile

        FileCopy Filename, DestName

        Lib_Forms = True

        Exit Function

    Out:

        'When the document does not exist in the library:

        MsgBox "Form does not exist in the Library. We are sorry but database will close now.", , _

            "So Sorry..."

    End Function

    In the macro that calls the Lib_Forms function, use Lib_Forms()=False as Condition for the StopAllMacros action.

    0 comments No comments
  3. Anonymous
    2014-04-17T20:06:16+00:00

    Public Function Lib_Forms() As Boolean

        Dim Filename As String

        Dim DestName As String

        Dim OrigPath As String

        Dim OrigFile As String

        On Local Error GoTo Out

        OrigPath = "L:\legalper\lib\forms"

        OrigFile = Form_DA.LibForm.Text             

        Dim DestFile As String

                If Forms!DA!DA = 2 Then

                    DestFile = "merge_li.docx"

                Else

                If Forms!DA!DA = 1 Then

                    DestFile = "merge_li.frm"

                End If

                End If

        DestName = Tmppath & DestFile

        Filename = OrigPath & OrigFile

        FileCopy Filename, DestName

        Exit Function

    Out:

    ‘When the document does not exist in the library:

    MsgBox "Form does not exist in the Library. We are sorry but database will close now.", , "So Sorry..."

    ‘This is where I put the END statement, but I see the macros of steps 5 and 6 continuing here and

    ‘since it’s an mde file, the macros error out and close the .mde file

    End Function

    0 comments No comments
  4. HansV 462.6K Reputation points MVP Volunteer Moderator
    2014-04-17T17:52:53+00:00

    Could you post the code for step 4?

    0 comments No comments
  5. Anonymous
    2014-04-17T16:27:50+00:00

    Sorry, I had already tried that before posting. It isn't working. I can see the "post vba" macros running,

    0 comments No comments