X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Stepping Through VBA Code    
post Jan 16 2017, 04:39 PM

Posts: 152
Joined: 29-November 13

Hi Guys,

I'm a newbie here so please be kind! grinhalo.gif

I'm using Access 2007 and would like to know if there is a simply way to have the VBA code displayed that is attached to a Form whilst I am using the form so that I can see the actual line of code that is being executed in real time?

I suppose you would call this "Stepping through" the code in real time.

Thanks for your help.

Go to the top of the page
post Jan 16 2017, 05:09 PM

UtterAccess Editor
Posts: 18,211
Joined: 29-March 05
From: Wisconsin


Probably the simplest thing to do would be to add a Breakpoint to one of the early lines of code in whichever event you're trying to work on. For example, if you have this for a combobox's NotInList event:

Private Sub lngAdditiveTypeID_NotInList(NewData As String, Response As Integer)

   Dim strSQL As String, strUOM As String
'   The user just entered a value that's not in the source table.
'   Prompt the user to verify that they wish to add the new value.
    If MsgBox("That is not in the list of Additive Types. Add it?", _
        vbOKCancel, "New Additive Type?") = vbOK Then

'       Get the unit of measure for the new additive type
        strUOM = InputBox("What is the Unit of Measure for this Additive Type " & _
                                                            "(Lbs, Gal, etc.)?", "UOM")

'       Set the Response argument to indicate that data is being added.
'       (This will automatically re-query the combobox when done.)
       Response = acDataErrAdded
'       Add the user-entered string (NewData) to the appropriate table.
       strSQL = "INSERT INTO tblAdditiveTypes( strAdditiveTypeName, strUOM ) " & _
                "VALUES (""" & NewData & """, """ & strUOM & """);"
       CurrentDb.Execute strSQL, dbFailOnError
   ' If user chooses Cancel, suppress the error message and undo changes.
       Response = acDataErrContinue
   End If

End Sub

You could click on the vertical grey stripe just to the left of the line reading "Response = acDataErrAdded", and you'll see that line of code highlighted with a brown stripe, and a brown circle will appear where you clicked on the grey stripe. Now you have a Breakpoint in your code. Next, you would open your form normally, and type a new value in the combobox. You'll be prompted by a messagebox, then an inputbox, like usual. Then, the code will halt at your breakpoint, and you can examine the values of the variables by hovering your cursor over the variable names within the code, to make sure they are storing what they should be storing.

You might want to check out this article by Chip Pearson that shows some basics about debugging VBA in Excel. A lot of what he talks about will apply to VBA in Access as well.

Hope this helps,


(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
post Jan 21 2017, 06:59 AM

Posts: 152
Joined: 29-November 13

Thanks mate!
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    20th March 2018 - 11:55 PM