Private Sub rosoom_AfterUpdate()

On Error GoTo Err_rosoom_Click

    Me.tot_pay.Value = Nz(Me.frmpayment.Form!tot_amount, 0)

Exit_rosoom_Click:

    Me.tot_rosoom.Value = Nz(Me.rosoom.Value, 0) + Nz(Me.bus.Value, 0) + Nz(Me.last_year.Value, 0) - Nz(Me.owner.Value, 0)
    Me.rest = Me.tot_rosoom.Value - Me.tot_pay.Value
    
    Exit Sub

Err_rosoom_Click:

    Forms!frmstudent!tot_pay = 0
    Resume Exit_rosoom_Click

End Sub

Private Sub last_year_AfterUpdate()

On Error GoTo Err_last_year_Click

    Me.tot_pay.Value = Nz(Me.frmpayment.Form!tot_amount, 0)

Exit_last_year_Click:

    Me.tot_rosoom.Value = Nz(Me.rosoom.Value, 0) + Nz(Me.bus.Value, 0) + Nz(Me.last_year.Value, 0) - Nz(Me.owner.Value, 0)
    Me.rest = Me.tot_rosoom.Value - Me.tot_pay.Value
    
    Exit Sub

Err_last_year_Click:

    Forms!frmstudent!tot_pay = 0
    Resume Exit_last_year_Click


End Sub

Private Sub owner_AfterUpdate()

On Error GoTo Err_owner_Click

    Me.tot_pay.Value = Nz(Me.frmpayment.Form!tot_amount, 0)

Exit_owner_Click:

    
    Me.tot_rosoom.Value = Nz(Me.rosoom.Value, 0) + Nz(Me.bus.Value, 0) + Nz(Me.last_year.Value, 0) - Nz(Me.owner.Value, 0)
    Me.rest = Me.tot_rosoom.Value - Me.tot_pay.Value
    
    Exit Sub

Err_owner_Click:

    Forms!frmstudent!tot_pay = 0
    Resume Exit_owner_Click


End Sub

Private Sub bus_AfterUpdate()

On Error GoTo Err_bus_Click

    Me.tot_pay.Value = Nz(Me.frmpayment.Form!tot_amount, 0)

Exit_bus_Click:

    Me.tot_rosoom.Value = Nz(Me.rosoom.Value, 0) + Nz(Me.bus.Value, 0) + Nz(Me.last_year.Value, 0) - Nz(Me.owner.Value, 0)
    Me.rest = Me.tot_rosoom.Value - Me.tot_pay.Value
    
    Exit Sub

Err_bus_Click:

    Forms!frmstudent!tot_pay = 0
    Resume Exit_bus_Click


End Sub

Sub CALC_PAY_TOT()

On Error GoTo xx

 '  DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    
    Dim TOT As Double
    Dim strSQL As String
    Dim rst As New ADODB.Recordset
    
    strSQL = "SELECT sum(amount)  FROM payment  WHERE student_Ser=" & Forms!frmstudent!student_ser
    
    rst.Open strSQL, CurrentProject.Connection, _
    adOpenKeyset, adLockOptimistic

    rst.MoveFirst
    TOT = rst.Fields(0)
    Forms!frmstudent!tot_pay = TOT
    rst.Close
   
calc_rest:
  
    Forms!frmstudent!tot_rosoom = Nz(Forms!frmstudent!rosoom, 0) _
    + Nz(Forms!frmstudent!bus, 0) _
    + Nz(Forms!frmstudent!last_year, 0) _
    - Nz(Forms!frmstudent!owner, 0)
    
    Forms!frmstudent!rest = Forms!frmstudent!tot_rosoom - Forms!frmstudent!tot_pay

    Exit Sub
xx:
    Forms!frmstudent!tot_pay = 0
    Resume calc_rest
End Sub


Sub DeleteRec1(frm As Form, FindStr As String)
    Dim rst As Recordset
    
    Style = vbYesNo 'vbOKCancel
    Title = "            ãÏÑÓÉ ÇáÞáã ÇáÃåáíÉ ááÈäÇÊ"    ' Define title.

    If MsgBox("     åÜÜÜá ÊÑíÜÜÜÏ ÍÜÜÜÜÐÝ ÇáÓÌÜÜÜÜÜá ÇáÍÜÜÜÜÜÜÇáì ¿     ", Style, Title) = _
       vbYes Then
    
        Set rst = frm.RecordsetClone
        rst.FindFirst FindStr
       
        rst.Delete
    
        DoCmd.RunCommand acCmdRefresh
        rst.Close
    Else
      
      ' read user licence
      user_licence
   
   ' when open form no add - no modify - no delete
     no_add_mod_del
 
        Exit Sub
    End If
End Sub



Private Sub tot_rosoom_BeforeUpdate(Cancel As Integer)

End Sub
