Lab for Week 12 - Step by Step

 

Very Busy (VB) Mail Order

This lab is very similar to Example 3 and emphasizes the use of Add Mode and how to Complete or Cancel the add operation. The button control for this simpler example is very easy to implement. You are in Add Mode when the user clicks Add, and you are back in Browse Mode when the user completes or cancels the operation. Completing the add means issuing an Update, while canceling the add means issuing a CancelUpdate.


Private Sub mnuRecordAddNew_Click()
    cmdSave.Enabled = True
    cmdCancel.Enabled = True

    datCustomer.Recordset.AddNew
    txtCustomerID.SetFocus

    mnuRecord.Enabled = False
    datCustomer.Enabled = False

End Sub

Private Sub cmdCancel_Click()
    datCustomer.Recordset.CancelUpdate

    cmdSave.Enabled = False
    cmdCancel.Enabled = False

    mnuRecord.Enabled = True
    datCustomer.Enabled = True

End Sub

Private Sub cmdSave_Click()
    If txtCustomerID.Text = "" Then
        MsgBox "You MUST enter a Customer ID", vbCritical + vbOKOnly, "Error Detected"
        txtCustomerID.SetFocus
        Exit Sub
    End If

    datCustomer.Recordset.Update

    cmdSave.Enabled = False
    cmdCancel.Enabled = False

    mnuRecord.Enabled = True
    datCustomer.Enabled = True

End Sub

 

Download the Completed Lab


Back to Week 12