Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Troubleshooting is the key to being a good Programmer

Access 101

Troubleshooting is the key to being a good Programmer

by  DougP  Posted    (Edited  )
Foreword:
Old computer saying ôSave as you goö applies today even more than before.
I always type in some code then save it, type in a few more lines and save it.
I start with a few lines then run them to see if I get the results I need or not. If I do then I add a line or two more and test it again. The first few lines I know already work so I can spend time on the next lines. I do this through the whole coding procedure. ItÆs far easier to fix one or two lines or decide that this function will not work at all, than to spend a lot of time coding and get to the bottom of 20 lines, and not have a clue why it did not work. Or worst yet have to start over with a different method or procedure.
Yes thatÆs life of a programmer a lot of it is trial and error.

Most of my programs don't work the first time I type in the VBA code either. But Access has some very good tools at your disposal.
1. The Immediate Window, Press Ctrl-G to bring up the immediate window in the VBA code view. This is where you can print the values of variables as the code is running. They will show up in the bottom half of the window. You Do this using Debug.Print YourVariable. You can put Debug.Print statements all over the place. The yellow code cursor must go passed the Debug.Print line before it will print. If you want to track several at a time but are not sure which one is printing what. Add a comment in front Debug.Print YourVariable
2. If you want to stop the code to examine something click on a line that does not start with DIM and press F9 key. It should put a RED line there. If it does not click on a line below it and try again. Most lines let you stop on them but not all do.
3. Once the program stops you can tap the F8 key to move to the next line. Hint: Tap it and wait a second, tap it again to move to the next line and wait again. The yellow code cursor will be on the line to execute next. The lines that will not let you press F9 on, pressing F8 will hop over them, this is normal and they ARE executed.
4. If you are done with code watching you can Press F5 and it will run all the way through.
5. While the code has stopped running you can Press Ctrl-G and then type ?variablename and hit the enter key to see the value(s) of the variable(s). You can also drag the yellow bar up or down the page and skip code or go back and re-run something. This is done by clicking in the far left column when you see a strange arrow. Click and drag it up or down. Note it may not let you stop on certain lines again.
6. You can make slight changes to the code and drag the yellow bar up try it again.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top