I hit the compile button every few lines of VBA code I enter

Compile button you ask?  Then you say “But I always have to go Debug and Compile Project.”  and “Sometimes I don’t even think of it.”

When in the VBA IDE I always have the debug menu visible.  I put it on the right hand side of the Standard Menu.  I then added the compile button to the Debug menu.

Do make very sure that you have the Require Variable Declarations check box on.  You get there from within the VBA Editor by Tools >> Options >> Editor tab.   Access 2000 in particular turns this off. 

This once cost me an hour of wasted effort while doing a very high pressure database on site during the last few weeks of building what was at that time North America’s largest every construction project.  It never occurred to me to look for Option Explicit not being present at the top of the VBA module.  GRRRR.  Fortunately MS turned that option back on in Access 2002 as I recall.

While you’re there I always turn the Auto Syntax Check off as every line that has a compile error gives you an annoying message box.  You should see the red line of code with an error.  But if you don’t then hitting the compile project button will show you the lines of code with errors.

VBAIDEWithCompile

And yes, that is MZ-Tools on the lower left hand side.

I find that working with the Toolbars to be quite non intuitive but I’m getting a bit better at it.  

1) To add the Debug Toolbar right click anywhere on the ToolBar and select the Debug Toolbar.  It will now be plopped (excellent techie term that) as a floating toolbar on your screen.  Drag it to the existing Toolbar and to the right hand side.

While you’re there add the Edit Toolbar too as it has some nice features too especially the comment and uncomment buttons. 

2) Right click anywhere on any ToolBar and choose Customize.  The Toolbar on the right hand side will move to the left.  This is only a temporary thing.

3) Click on the Commands Tab and click on the Debug Category in the left hand list box. 

VBAIDEWithDebug

4) On the right hand list box you will see Compile Project as the first item.  Drag and drop it onto the Debug menu.

5) Close and you’re done.

This was all done in Access 2000 so other versions of Access might be slightly different.

Thanks go to TechSmith for their free MVP license for SnagIt.  Took me a minute or two to figure out the best way of snagging the toolbar but after that it was effortless.   Nice user interface and quite easy to use.  It was quite easy to add the red arrow too.    And I’ve never used SnagIt before either.   It was a lot less effort than using Ctrl+Print Screen, MS Paint to paste the image into and a graphics tool to resize the jpg.

4 thoughts on “I hit the compile button every few lines of VBA code I enter”

  1. Good suggestion. I haven’t used break points for years. There was a problem with them in some version of Access, 2000 I think, where they just wouldn’t go away. So I started using explicit Stop lines in the code. If I forget and leave them in there MDEs ignore them.

  2. Hi Tony,

    re: Option Explicit

    “Fortunately MS turned that option back on in Access 2002 as I recall.”

    I did not use 2002, but to the best of my knowledge, Option Explicit has not been included by default in any version … an important setting I always change when starting a database (also set Tab Width to 3 instead of 4).  

    Like you, if code is already there, I add Option Explicit to the top of each module I work on if it is not there — and meticulously go and declare all the variables that are used and not DIMensioned… or correct them <smile>  – and fix all references or comment them

    ~~~

    “turn the Auto Syntax Check off “

    I like to leave it on … if I decide not to finish a statement (like IF or a loop or to go to the top and Dim another variable) so that the compiler wont’ bark,  press [Home] to go to the beginning of the line and comment it … In a property, use empty quotes so you can pop out to the database window and do the Rename/Copy/Paste thing <smile>

    I also use these short-cut keys a lot:

    F8 — Single-Step each statement

    Shift-F8 — Step-Over

    Ctrl-Shift-F8 — Step Out

    F5 — continue execution

    Ctrl-Up — goto top of current procedure or previous procedure

    Ctrl-Down — goto top of next procedure

    Ctrl-Spacebar — make IntelliSense come back on

    for debugging, I found this paper very good:

    Access, VBA, and Visual Basic Debugging Tips and Techniques

    by Luke Chung, President of FMS

    http://www.fmsinc.com/…/Debug.asp

    All these years and I never knew about the Edit toolbar — now I use it all the time!  Don’t know how I lived without commenting/uncommenting a block at a time!

    Also got some great information from “Access 2007 VBA Programmer’s Reference” by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, and Armen Stein … like turning on the Locals Window and Shift-F2 to View Definition … more neat things that I just never explored!  The book is very well written and packed with good stuff.

    (Dan, I use BreakPoints a lot, thanks for the Clear All BreakPoints button tip … I saw it when I was adding buttons but for some reason did not add it — now I have!)

    Warm Regards,

    Crystal

    *

        (:  have an awesome day  :)

    *

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>