Project Perfect
PROJECT  PERFECT
                 Project Management Information
                          Specialists in Project Infrastructure

Example of Microsoft Access Code Comments

The following is an example of thoroughly documented code. It is an extract from a program we produced for a client. You do not have to be a VBA expert, but you can see by the layout and the comments in green, that a Microsoft Access Developer can read through the code and see each step with an explanation. The benefit is that code is easier to modify and debug. This is true not only for other people who may work on it, but also for the original MS Access developer who may not have looked at the code for months or even years.

RecFound:
'--------------------------------------------
' Find the previous record details

rst.MovePrevious                             ' Move to the previous record

'--------------------------------------------
' Check the record to be moved is not the first record. Cannot move 1st record up
' If it is not the first, update the record sequence number

If Not rst.BOF Then                          ' Not the first record so continue
        intPreviousRecNo = rst![TaskNo]     ' Previous record number
        intPreviousSeqNo = rst![MSPID]      ' Previous sequence number

        '--------------------------------------------
        ' Update the previous record

         strSQL = "UPDATE tblTask" & _
        " SET MSPID = " & intCurrentSeqNo & _
        " WHERE tblTask.TaskNo = " & intPreviousRecNo & ";"
         subRunUpdateQuery (strSQL)       ' Run the update query for current record

        '--------------------------------------------
        ' Update the selected record sequence number

        strSQL = "UPDATE tblTask" & _
        " SET MSPID = " & intPreviousSeqNo & _
        " WHERE tblTask.TaskNo = " & intCurrentRecNo & ";"
        subRunUpdateQuery (strSQL)           ' Update the previous record

        '--------------------------------------------
        ' Position the cursor on the moved record

        Me![frmGanttDataSub].Requery
        With Me.frmGanttDataSub.Form
             .Recordset.FindFirst "TaskNo=" & intCurrentRecNo
        End With
    Else
         ' You tried to move the first record up
         Call MsgBox("You have reached the start of the list. You cannot move the                          selected record. Press OK to continue.", vbCritical, "Start of List")
End If

'--------------------------------------------

.

Return to the top