How do I use debug?

dewsbury

Registered User.
Local time
Today, 05:11
Joined
Jul 4, 2008
Messages
57
Hi,

Beginner here with programming background.

I have a few little bits of code that are activated on form properties such as "Before Update" or "On Double Click".

These bits of code generally work well.
However, now it does not!

How can I debug my code?
I have tried experimenting with the VBA options but I seem to be missing something .
 
If you click in the left margin by a line of code you should see a blob appear. the code will pause when it reaches that point. You can step it through one line at a time by pressing the F8 key. Press the F5 key to resume normal running
 
I personally like adding an Error section at the bottom and then catching the error as soon as I see the code jump to the bottom of the section. Example - in the following, the line me.textbox1.enabled = false will cause and error and jump to the "on error" section at the bottom:
Code:
private sub cmd_click

on error go to ErrSection

  me.textbox1.setfocus
    me.textbox1.enabled = false

exit sub

ErrSection:
  msgbox "You have encountered an error: " & err.number & " " & err.description

end sub
clicking through this sub one line at a time like Rabbie has suggested will show the yellow highlight skip to the bottom as soon as you reach the "enabled" property line in the procedure. Just an example of how to debug for you...
 
There are many ways to debug. Here is another if you have a huge amount of complex code. It also helps in testing. here is an example:
Code:
......(dim's)
Dim bolTest as Boolean
bolTest = True
....Code
If bolTest = True then MsgBox "Got Here #1 ... My Total =" &  curTotal
....Code
If bolTest = True then MsgBox "Got Here #2 ... My Total =" &  curTotal
....Code
etc

The bolTest could be made into a global variable as well and used universally. If you code a hot key in the form to toggle strTest, you can turn the messages on and off by hitting the key combo (EG Alt/Shift/F12) on the form. As the code executes the mesgbox messages will appear as they are encountered when the value is True and will not effect your production code when false. So you can publish with them. It helps a lot when you get that phone call saying "It doesn't work".

Smiles
Bob
 
Thank you all.

It's easy when you know how !
PLenty of useful info provided.

My coding will be very simple so the debugging will be easy.

Thanks again.
 

Users who are viewing this thread

Back
Top Bottom