what would be the best solution for this code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chel1414
    New Member
    • Sep 2014
    • 1

    #1

    what would be the best solution for this code

    Code:
    Private Sub cmdAdd_Click()
    Dim NetPay As Double
       If cmdAdd.Caption = "Add" Then
          Adodc1.Recordset.AddNew
          cmdAdd.Caption = "Save"
          cmdUpdate.Enabled = False
          cmdDel.Enabled = False
      Else
          Text9 = Val(txtSSS.Text) + Val(txtTAX.Text) + Val(txtPhilHealth.Text) + Val(txtPagibig.Text) + Val(txtCanteen.Text) + Val(txtOthers.Text)
          TotalDeduction = Format(txtTotalDeduction, "00.00")
          Adodc1.Recordset.Fields("TotalDeduction") = TotalDeduction
          Adodc1.Recordset.Update
          cmdAdd.Caption = "Add"
          cmdUpdate.Enabled = True
          cmdDel.Enabled = True
       End If
    End Sub
    
    Private Sub cmdDel_Click()
        Adodc1.Recordset.Delete
        Adodc1.Recordset.Requery
    End Sub
    
    Private Sub cmdUpdate_Click()
        Text10 = Val(txtGrossPay.Text) - Val(txttd.Text)
        Adodc1.Recordset.Update
        
    End Sub
    
    Private Sub cmdTotalDeduction_Click()
    'to add the value in text 3, text 4, text 5, text 6, text 7, text 8
    txtTotalDeduction = Val(txtSSS.Text) + Val(txtTAX.Text) + Val(txtPhilHealth.Text) + Val(txtPagibig.Text) + Val(txtCanteen.Text) + Val(txtOthers.Text)
    'display the amount in text 9
    Text9 = Format(txtTotalDeduction, "00.00")
    
    End Sub
    
    Private Sub cmdNetPay_Click()
    'to minus the value in tex box 2 by text box 9
    txtNetPay = Val(txtGrossPay.Text) - Val(txtTotalDeduction.Text)
    'display the amount in text box 10
    Text10 = Format(txtNetPay, "00.00")
    End Sub
    Attached Files
    Last edited by Rabbit; Sep 23 '14, 05:27 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    The error message is pretty clear. You added a new record but didn't populate the primary key.

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3665

      #3
      chel1414,

      Is your Primary Key set up as an AutoNumber? This would fix the problem immediately.

      Comment

      Working...