> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Set a Breakpoint in Startup Code in VBA
- URL: https://nolongerset.com/breakpoints-in-vba-startup-code/
- Published: 2021-12-04T21:48:31.000Z
- Updated: 2026-05-08T13:01:00.000Z
- Description: Ever set a breakpoint in your Access application's startup code, only to have it get cleared before it got hit? There's a simple workaround.
- Author: Mike Wolfe
- Tags: Debugging, Basic, #Import 2026-05-20 02:59

[Breakpoints](https://docs.microsoft.com/en-us/office/vba/language/how-to/set-and-clear-a-breakpoint) are a handy tool to help you debug your code.

But what if you want to **debug the code that runs automatically** when your application starts? Can't you just use a breakpoint there? And if the answer to that question is, "No" (it is), then *why* won't it work and what is the *workaround*?

Spoiler alert: the answer to that last question is the VBA [**Stop** statement](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/stop-statement).

## Closing Access Clears All Breakpoints

When you close and reopen an Access application (or Excel workbook, Word document, etc.), any breakpoints that you have set in the application's VBA code get cleared. As a consequence, it's impossible to set a breakpoint in your application's startup code.

## "Startup" Code in Microsoft Access

What exactly do I mean by "startup" code in an Access application?

There is no special "Main" procedure that gets run automatically as there is in some other languages. In Access, there are two ways to write code that runs automatically when the application starts:

- Form\_Open and/or Form\_Load event code in the startup form
- Code that gets called from the **Autoexec** macro

## Startup Form

You can designate a startup form for your application via the Access Options dialog box:

**File > Options > Current Database > Display Form**

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/12/image-4.png)

The startup form is generally either a hidden [Global form](https://nolongerset.com/the-global-form/) or a Main Menu form (if you use form-driven navigation).

If you add event-handling code for that form's Open and/or Load event, then it will be executed every time the user starts your application.

## AutoExec Macro

The other way to set code to run at application startup is via the special ["AutoExec" macro](https://support.microsoft.com/en-us/office/create-a-macro-that-runs-when-you-open-a-database-98ba1508-dcc6-4e0f-9698-a4755e548124). 

Along with "[AutoKeys](https://support.microsoft.com/en-us/office/run-an-access-macro-by-using-a-keyboard-shortcut-0d267570-d3da-46eb-9bfb-a3c81af676be)," the "AutoExec" macro is one of two macros that gain special powers based purely on their names. When an Access application starts up, it looks for a macro named AutoExec. If such a macro exists, it gets executed.

In Access applications with both a **Startup Form** and an **AutoExec Macro**, the Startup Form opens (and executes any code in its various event handlers) ***before*** the AutoExec Macro runs.

Rather than rely on the Form Load/Open events of a startup form, I prefer to put my application initialization code in a **public function** named Startup. I then call this function as the only step in an AutoExec macro.

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/12/image-5.png)

The startup function itself is usually nothing fancy. Here's a sample:

```vba
Public Function Startup()
    
    'Initialize the global vbWatchdog error handler
    EnableVBWatchdog
    
    'Open and hide the global form
    DoCmd.OpenForm "Global", WindowMode:=acHidden
    
    'Other application initialization code
    
End Function
```

I prefer not to set a Startup Form in the current database options, as launching it from my `Startup` function gives me complete control over the process.

## Stop Right There!

So what happens if my application suddenly starts crashing right at startup?

My first thought would be to put a breakpoint on the first executable line of code, the **Startup** function signature, like so:

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/12/image-6.png)

Unfortunately, as discussed above, when I close my application the breakpoint I set will be cleared. 

The simplest way to work around this limitation is to add the `Stop` statement to the top of the public function. This acts just like a breakpoint, except that it won't get cleared when the application closes.

Now, when we restart the application, the Stop statement halts execution and allows us to step through the problematic code:

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/12/image-7.png)

## Stop Statement Ignored in Runtime Mode

Like the [Debug.Assert method](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/assert-method), the **Stop** statement gets ignored when executing your Access application in [runtime mode](https://nolongerset.com/runtime-mode-in-microsoft-access/). In other words, the program will skip right over that line of code as if it isn't even there.

---

### External references

[Set and clear a breakpoint (VBA)Office VBA reference topicMicrosoft Docso365devx![](https://docs.microsoft.com/en-us/media/logos/logo-ms-social.png)](https://docs.microsoft.com/en-us/office/vba/language/how-to/set-and-clear-a-breakpoint)

[Stop statement (VBA)Office VBA reference topicMicrosoft Docso365devx![](https://docs.microsoft.com/en-us/media/logos/logo-ms-social.png)](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/stop-statement)

[Create a macro that runs when you open a databaseLearn how to create an AutoExec macro that runs every time you start a database.![](https://support.microsoft.com/apple-touch-icon.png)![](https://support.microsoft.com/images/Facebook-GrayScale.png)](https://support.microsoft.com/en-us/office/create-a-macro-that-runs-when-you-open-a-database-98ba1508-dcc6-4e0f-9698-a4755e548124)

[Run an Access macro by using a keyboard shortcut![](https://support.microsoft.com/apple-touch-icon.png)![](https://support.content.office.net/en-us/media/4fbc804e-6476-4de6-9816-55f1c7122be3.gif)](https://support.microsoft.com/en-us/office/run-an-access-macro-by-using-a-keyboard-shortcut-0d267570-d3da-46eb-9bfb-a3c81af676be)

[Assert method (Visual Basic for Applications)Office VBA reference topicMicrosoft Docso365devx![](https://docs.microsoft.com/en-us/media/logos/logo-ms-social.png)](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/assert-method)

### Referenced articles

[The Global FormStoring global variables on a hidden form has some distinct advantages over storing them in VBA.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/01/rustic-3441673_1920.jpg)](https://nolongerset.com/the-global-form/)

[Runtime Mode in Microsoft AccessThere are two ways to force a full version of Access to run a front-end file in runtime mode: the /runtime switch and changing the extension to .accdr.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/08/landscape-78058_1920.jpg)](https://nolongerset.com/runtime-mode-in-microsoft-access/)

*Image by [Walter Knerr](https://pixabay.com/users/knerri61-772758/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=634941) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=634941)*