Adding Line Numbers To Your Code

You probably know you can comment your code using the apostrophe character or the REM statement. Did you know that you could number your lines of code? You can, and it's easy. Just add the number to the beginning of each line of code. For instance, the procedure

Private Function GetCount()
Dim db As Database, strSQL As String, rst As Recordset
Set db = CurrentDb
strSQL = "SELECT Count(*) FROM table3"
Set rst = db.OpenRecordset(strSQL)
Debug.Print rst(0)
End Function

becomes,

Private Function GetCount()
10 Dim db As Database, strSQL As String, rst As Recordset 20 Set db = CurrentDb
30 strSQL = "SELECT Count(*) FROM table3"
40 Set rst = db.OpenRecordset(strSQL)
50 Debug.Print rst(0)
End Function

There are only a few rules to remember when numbering your code:

* Numbers must appear at the very beginning of your line of code.
* Each number must be unique within the module (which is a nuisance).
* Don't number the beginning or ending statement.

Access Index

Main Index

Tips Index