INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Access 101

Troubleshooting is the key to being a good Programmer by DougP
Posted: 14 Dec 00 (Edited 23 Mar 02)

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.

Back to Microsoft: Access Other topics FAQ Index
Back to Microsoft: Access Other topics Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close