Few if any of us write code that is accurate and logical 100% of the time.
Always attempt to
compile your code after every change. This is accomplished by selecting
Debug->Compi
le [name of module]. Logic errors will not be detected however misspelled memory variables or other syntax errors should be caught.
It is also important to include Option Explicit at the top of every code module:
[code VBA]Option Compare Database
Option Explicit[/code]
If your code doesn't work as expected, you need to be able to debug it. For instance, if one of the early lines of your code is:
Code:
stQueryName = Me.[cmbQueryName]
and it doesn't seem to be working correctly, you have at least three options for trouble-shooting.
Adding a breakpoint is as simple as clicking in the vertical bar to the left of a line of executable code.
Code:
|[red][b]o[/b][/red]| [color white red][b]stQueryName = Me.[cmbQueryName][/b][/color]
The code will stop running and allow you to hover the mouse over a variable to see its value. You can press [F8] to step through the code a line at a time. [F5] will run to the end of the procedure.
The following will put the value in the debug window:
Code:
stQueryName = Me.[cmbQueryName]
Debug.Print "stQueryName: " & stQueryName
You can press Ctrl+G to open the debug window to view the results of the statement.
The following will stop the code execution and display the value in a message box:
Code:
stQueryName = Me.[cmbQueryName]
MsgBox "stQueryName: " & stQueryName