وعليكم السلام ورحمة الله وبركاته ،،
جرب هذا التعديل أخي ، وأخبرني بالنتيجة سريعاً ..
Private Sub أمر8_Click()
Dim sql As DAO.Recordset
Dim rsInvoice As DAO.Recordset
Dim strAmount As String
Dim Amount As Double
Dim i As Integer
Dim exists As Boolean
Dim rsCheck As DAO.Recordset
Dim strSQL As String
Dim invoiceNumber As Long
Dim invoiceDate As Date
Dim totalInstallments As Integer
Dim currentInstallmentDate As Date
Set rsInvoice = CurrentDb.OpenRecordset("SELECT * FROM g1", dbOpenDynaset)
Set sql = CurrentDb.OpenRecordset("G2", dbOpenDynaset)
Do Until rsInvoice.EOF
invoiceNumber = rsInvoice![G1_NO]
invoiceDate = rsInvoice![G1_DATE]
totalInstallments = rsInvoice![G1_NO_PAYMENTS]
Amount = Round(rsInvoice![G1_AMOUNT] / totalInstallments, 2)
strAmount = NoToTxt(Amount, "فلس", "دينار")
For i = 0 To totalInstallments - 1
exists = False
currentInstallmentDate = DateAdd("m", i, invoiceDate)
strSQL = "SELECT * FROM G2 WHERE [G2_NO] = " & invoiceNumber & " AND [G2_DATE] = #" & Format(currentInstallmentDate, "yyyy-mm-dd") & "#"
Set rsCheck = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
If Not rsCheck.EOF Then
exists = True
End If
rsCheck.close
Set rsCheck = Nothing
If Not exists Then
With sql
.AddNew
![G2_NO] = invoiceNumber
![G2_DATE] = currentInstallmentDate
![G2_INSTALMENT_AMOUNT] = Amount
![G2_AMOUNT_WORDS] = strAmount
![G2_INSTALMENT_STATUS] = "لم يتم الدفع"
.Update
End With
End If
Next i
rsInvoice.MoveNext
Loop
sql.close
Set sql = Nothing
rsInvoice.close
Set rsInvoice = Nothing
End Sub