Private Sub Command1_Click()
Dim I As Integer
For I = 1 To fox.Rows - 1
If Trim$(fox.TextMatrix(I, 0)) <> "" And Val(Trim$(fox.TextMatrix(I, 0))) > 0 Then
Set RS = New ADODB.Recordset
If RS.State = adStateOpen Then RS.Close
RS.CursorLocation = adUseClient
ms = MsgBox("هل تريد بالفعل حفظ بيانات الفاتورة", vbYesNo)
If ms = vbYes Then
RS.Open "select* from BillItems ", DB, adOpenStatic, adLockPessimistic
RS.AddNew
RS!Id = Val(Trim$(fox.TextMatrix(I, 0)))
RS!Name = Trim$(fox.TextMatrix(I, 1))
RS!Qty = Val(Trim$(fox.TextMatrix(I, 3))) '3
RS.Update
DoEvents
Set RS2 = New ADODB.Recordset
If RS2.State = adStateOpen Then RS2.Close
RS2.CursorLocation = adUseClient
RS2.Open "Select * From Store Where iD=" & Val(Trim$(fox.TextMatrix(I, 0))), DB, adOpenStatic, adLockPessimistic
If RS2.RecordCount > 0 Then
RS2![noo] = RS2![noo] - Val(Trim$(fox.TextMatrix(I, 3))) '3
RS2.Update
DoEvents
MsgBox "تمت عملية حفظ الفاتورة ", vbMsgBoxRtlReading + vbInformation, "تنبية"
Else
MsgBox "لم يتم حفظ الفاتورة ", vbMsgBoxRtlReading + vbInformation, "تنبية"
Exit Sub
End If
End If
End If
Next
End Sub