Kod:
Sub FazlaDagit(Optional Kimlik As String = "")
Dim Fazla As New ADODB.Recordset
Dim Borc As New ADODB.Recordset
Dim SqlFazla, SqlBorc, txtKimlik, SqlGuncelle As String
Dim dblBakiye, dblBorc, dblVerilen As Double
txtKimlik = IIf(Kimlik = "", "", " AND ((TBLUYEGENELBIL.KIMID)=" & Kimlik & ")")
SqlFazla = " SELECT TBLUYEGENELBIL.KIMID, TBLUYEGENELBIL.KalanPara" & _
" FROM TBLUYEGENELBIL " & _
" WHERE (((TBLUYEGENELBIL.KalanPara)>0)" & txtKimlik & ")"
Fazla.Open SqlFazla, CurrentProject.Connection, adOpenKeyset, adLockOptimistic 'burada açtığın bağlantı
If Fazla.RecordCount <= 0 Then GoTo 10 ' goto 10 ile kapanmadan
Fazla.MoveLast
Fazla.MoveFirst
Do Until Fazla.EOF
dblBakiye = 0
dblBakiye = Fazla.Fields("KalanPara")
SqlBorc = " SELECT TBLUYEODEMETABLOSU.KIMID, TBLUYEODEMETABLOSU.sira, TBLUYEODEMETABLOSU.TaksitMik, TBLUYEODEMETABLOSU.OdemeMik " & _
" FROM TBLUYEODEMETABLOSU " & _
" WHERE (((TBLUYEODEMETABLOSU.OdemeMik) < TBLUYEODEMETABLOSU.TaksitMik) And ((TBLUYEODEMETABLOSU.KIMID) =" & Fazla.Fields("KIMID") & ")) " & _
" ORDER BY TBLUYEODEMETABLOSU.SonOdemeTar"
Borc.Open SqlBorc, CurrentProject.Connection, adOpenKeyset, adLockOptimistic 'burada açtığın bağlantı
If Borc.RecordCount <= 0 Then GoTo 20 ' goto 10 ile kapanmadan
Borc.MoveLast
Borc.MoveFirst
dblVerilen = Nz(Forms!frm_anamenu!frm_UYEGENEL.Form!FRM_UYEODEMETABLOSU.Form!txtVerilen, 0)
'
Do Until Borc.EOF
If dblBakiye <= 0 Then GoTo 20
dblBorc = 0
dblBorc = Borc.Fields("TaksitMik") - Borc.Fields("OdemeMik") 'ödenmesi gereken
dblx = IIf(dblBakiye >= dblBorc, dblBorc, dblBakiye)
dblBakiye = dblBakiye - dblx
txtKaynak = IIf(dblVerilen < dblx, " kalan " & dblBakiye + dblx, " tarihinde yatan " & dblVerilen)
txtNot = Date & txtKaynak & " TL''den " & dblx & " lira ödendi "
SqlGuncelle = " update TBLUYEODEMETABLOSU set " & _
" OdemeMik=OdemeMik + ccur('" & dblx & "'), " & _
" OdenenTar=cdate(" & CLng(Date) & ")," & _
" Not='" & Nz(txtNot, "") & _
"' where sira=" & Borc.Fields("sira")
CurrentDb.Execute SqlGuncelle
dblVerilen = dblVerilen - dblx
SqlGuncelle = " update TBLUYEGENELBIL set " & _
" KalanPara=KalanPara - ccur('" & dblx & "') " & _
" where KIMID=" & Fazla.Fields("KIMID")
CurrentDb.Execute SqlGuncelle
Borc.MoveNext
Loop
20 '
Borc.Close
Set Borc = Nothing
Fazla.MoveNext
Loop
10
Fazla.Close
Set Fazla = Nothing
End Sub