Listing 33.8 --  33LIST08.TXT -- Edycja wiersza przegldarki

Private Sub btnUpdate_Click()
  grdChkReg.Text = Format(txtInput, "#,##0.00")
  saverow = grdChkReg.Row
  savecol = grdChkReg.Col
  SQLSTR = "Select * from LineItem where AccountKey = " & current_account & " order by [entry date]"
  Set ChkSet = ChkDb.OpenRecordset(SQLSTR, dbOpenDynaset)
  Set paySet = ChkDb.OpenRecordset("Payee", dbOpenDynaset)
  grdChkReg.Col = 0
  ChkSet.FindFirst "itemkey = " & grdChkReg.Text
  grdChkReg.Col = savecol
  ChkSet.Edit

  Select Case savecol
    Case 1
      ChkSet("chknum") = grdChkReg.Text
    Case 2
      ChkSet("entry date") = grdChkReg.Text
    Case 3
      paySet.FindFirst "payeeid = " & ChkSet("payeekey")
      If Not paySet.NoMatch Then
        paySet.Edit
        paySet("payeename") = grdChkReg.Text
        paySet.Update
      End If
      paySet.Close
    Case 4
      ChkSet("amtpayed") = grdChkReg.Text
      If ChkSet("amtpayed") > 0 Then
        ChkSet("entrytype") = "C"
        ChkSet("amtdeposit") = 0
        grdChkReg.Col = 5
        grdChkReg.Text = "0.00"
        grdChkReg.Col = savecol
      End If
    Case 5
      ChkSet("amtdeposit") = grdChkReg.Text
      If ChkSet("amtpayed") > 0 Then
        ChkSet("entrytype") = "D"
        ChkSet("amtpayed") = 0
        grdChkReg.Col = 4
        grdChkReg.Text = "0.00"
        grdChkReg.Col = savecol
      End If
  End Select
  ChkSet.Update
  ChkSet.Close
  If grdChkReg.Col = 4 Or grdChkReg.Col = 5 Then
    bal_amount = Val(txtInput)
    If savecol = 4 Then
      bal_amount = bal_amount * (-1)
    End If
    If grdChkReg.Rows > 2 Then
      grdChkReg.Row = saverow - 1
      grdChkReg.Col = 6
      bal_amount = bal_amount + Val(grdChkReg.Text)
      grdChkReg.Row = saverow
      grdChkReg.Text = Format(bal_amount, "#,##0.00")
      For I = saverow + 1 To grdChkReg.Rows - 1
        grdChkReg.Row = I
        grdChkReg.Col = 4
        bal_amount = bal_amount - Val(grdChkReg.Text)
        grdChkReg.Col = 5
        bal_amount = bal_amount + Val(grdChkReg.Text)
        grdChkReg.Col = 6
        grdChkReg.Text = Format(bal_amount, "#,##0.00")
      Next I
    Else
      grdChkReg.Col = 6
      grdChkReg.Text = Format(bal_amount, "#,##0.00")
    End If
    CkBkMain.lblBalance.Caption = Format(bal_amount, "#,##0.00")
  End If
  txtInput.Text = ""
  btnUpdate.Enabled = False
End Sub
