> ## 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.

# Compile Errors
- URL: https://nolongerset.com/compile-errors/
- Published: 2021-08-07T02:30:44.000Z
- Updated: 2026-05-08T13:03:08.000Z
- Description: Compile errors are easy to keep out of deployed code (just remember to Debug > Compile). Which is good because they hard crash Access in Runtime mode.
- Author: Mike Wolfe
- Tags: Bug Types, #Import 2026-05-20 02:59

*This is part 2 of a [7-part series](https://nolongerset.com/some-bugs-are-better-than-others/) comparing different kinds of software bugs.*

## What is a Compile Error?

Visual Basic for Applications (VBA) is a high-level programming language. 

Processors have a limited set of instructions that they can execute. The process of translating high-level (human-friendly) programming language code into low-level (CPU-friendly) machine code is known as compilation.

*NOTE: When you "compile" VBA, you're not actually compiling it all the way down to machine code. Rather, you are converting it into an intermediate layer known as byte-code or "P-Code". But that's a story for another day.*

Translating high-level code to low-level instructions is a computationally expensive process. The main reason for compiling code is to improve runtime performance. A side benefit is that compiled code is harder to plagiarize, though I personally think this is overrated (especially for custom software).

## Causes of Compile Errors

As part of the compilation process, VBA will check to make sure that the code you wrote will run when translated into machine code. 

For example, if you write a subroutine that takes a `String` as an argument passed by reference, but then try to call it with a variable of the `Date` data type, VBA will complain when you attempt to compile the code.

That's because when the code executes, the `MyDay` variable and the `Bar` variable will both be pointing to the [same address in memory](https://nolongerset.com/one-if-by-val-two-if-by-ref/). A memory location cannot simultaneously be two different data types, so the VBA compiler raises an error.

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

"ByRef argument type mismatch." If you read that error message carefully, you will note that this is only a compile error because the value is being passed by reference. If you change it to `(ByVal Bar As String)` or call Foo with a literal date (`#8/6/2021#`) or wrap the MyDay variable in parentheses `Foo (MyDay)`, then the compile error goes away. (Note: I'm not suggesting those are fixes! Rather, I'm pointing out another quirk of the ByRef vs. ByVal dynamic).

Note that in the screenshot above, none of the text is highlighted in red. That's because the above code is an example of a compile error, but it is not a [syntax error](https://nolongerset.com/syntax-errors/).

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/08/2021-08-06-21_36_01-mjw20-Window.png)

All syntax errors are compile errors. Not all compile errors are syntax errors.

## Consequences of Compile Errors

Non-syntax compile errors are not immediately made obvious while you are writing your code. 

To force a check for compile errors, you can go to Debug > Compile (\[Alt\] + \[D\], \[L\]). This is a good habit to get into while writing VBA. The compile process runs extremely fast in VBA (under one second) even for very large projects. That's mainly because only changed modules get compiled.

There is one major caveat. If you forget to explicitly compile your code, then you run the risk of publishing a front-end file with an embedded compile error. If that happens, then Access will hard crash in Runtime mode when it hits that error *even if you are using [vbWatchdog](https://nolongerset.com/error-handling-evolution/).*

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

Not the most helpful of error messages. **Always compile before deployment!** (Even if you don't deploy compiled .accde or .mde front-ends.)

Here's some sample code and a short video that illustrates the difference in how vbWatchdog automatically handles a runtime error versus what happens when your code encounters a compile error.

```vba
'--== code-behind of the auto-opening form ==--
Option Compare Database
Option Explicit

Private Sub Form_Load()
    ErrEx.Enable "Dummy" 'Step 1.  Enable vbWatchdog
    
    MsgBox "test"        'Step 2.  Show message box
    
    Debug.Print 1 / 0    'Step 3.  Runtime error
    
    TestFoo              'Step 4.  Compile error  --> hard crash
    
End Sub

Sub Foo(Bar As String)

End Sub

Sub TestFoo()
    Dim MyDay As Date
    Foo MyDay
End Sub
```

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/08/Compile-Error.gif)

Not even vbWatchdog can save you from your compile errors.

---

### External references

[Machine code - Wikipedia![](https://en.wikipedia.org/static/apple-touch/wikipedia.png)Wikimedia Foundation, Inc.Contributors to Wikimedia projects![](https://upload.wikimedia.org/wikipedia/commons/thumb/c/c0/W65C816S_Machine_Code_Monitor.jpeg/1200px-W65C816S_Machine_Code_Monitor.jpeg)](https://en.wikipedia.org/wiki/Machine%5Fcode)

[Instruction set architecture - Wikipedia![](https://en.wikipedia.org/static/apple-touch/wikipedia.png)Wikimedia Foundation, Inc.Contributors to Wikimedia projects![](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Mips32_addi.svg/370px-Mips32_addi.svg.png)](https://en.wikipedia.org/wiki/Instruction%5Fset%5Farchitecture)

### Referenced articles

[Some Bugs are Better than OthersNot all bugs are created equal. Avoid the expensive ones by making more of the ones that are easy to find and fix.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/car-2122580_1920.jpg)](https://nolongerset.com/some-bugs-are-better-than-others/)

[One if ByRef, and Two if ByValArguments in VBA are passed by reference by default. What does that mean? And what are the differences between passing by reference and by value?![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2020/09/lantern-1864627_1920.jpg)](https://nolongerset.com/one-if-by-val-two-if-by-ref/)

[Syntax ErrorsEvery programming language has its own syntactical quirks. The C family loves braces. Python loves indentation. BASIC loves words. And Perl loves #%@!{}\]&.![](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/vw-4868785_1920.jpg)](https://nolongerset.com/syntax-errors/)

[Error Handling EvolutionHow you handle errors says a lot about you as a programmer. Most people evolve with experience in how they handle errors. From the most naïve to the most advanced, here is what that evolution looks like.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2020/09/evolution-4107273_1920.jpg)](https://nolongerset.com/error-handling-evolution/)

*Image by [Ernie A. Stephens](https://pixabay.com/users/ernie114-7088342/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=4220406) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=4220406)*