0
我有一個擁有1000多條記錄並且數據類似的數據庫。我使用Access.Form輸入用於計算的值,並且我希望根據這些計算在每個記錄的表中進行數據更新,以便我可以將它用於報告。通過DAO記錄集環路
我不能讓這段代碼循環通過DAO.Recordset。我得到的數據與第一條記錄相同。
Dim MyDB As DAO.Database
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Contacts")
rs.MoveFirst
Do Until rs.EOF
rs.Edit
Dim a1 As Double
Dim a2 As Double
Dim a3 As Double
Dim a4 As Double
Dim a5 As Double
Dim a6 As Double
Dim a7 As Double
Dim a8 As Double
Dim a9 As Double
Dim a10 As Double
Dim a11 As Double
Dim a12 As Double
Dim a13 As Double
Dim a14 As Double
Dim a15 As Double
Dim a16 As Double
Dim a17 As Double
Dim a18 As Double
Dim a19 As Double
Dim a20 As Double
Dim a21 As Double
Dim a22 As Double
Dim a23 As Double
Dim c1 As Date
Dim c2 As Date
Dim c3 As Date
Dim c4 As Date
Dim b1 As Date
Dim b2 As Date
Dim b3 As Double
Dim b4 As Double
Dim b5 As Double
Dim d1 As Date
Dim d2 As Date
Dim d3 As Date
Dim d4 As Date
Dim d5 As Date
Dim d6 As Date
Dim d7 As Double
Dim d8 As Double
Dim d9 As Double
Dim d10 As Double
d1 = Text541.Value
d2 = Text542.Value
d3 = [Datum_Ugovora]
d4 = [Anex_Datum_OD]
d5 = [Raskid_Ugovora]
d6 = [Odjava_Sa_Ino]
d7 = [Satnica_SRB]
d8 = [Broj_Sati_SRB]
d9 = [Satnica_EUR]
d10 = [Broj_Sati_INO]
If d1 >= d3 And d1 <= d5 Then 'ugovor OD
c1 = d1
ElseIf d1 < d3 And Month(d1) = Month(d3) Then
c1 = d3
Else
c1 = 0
End If
If d2 >= d3 And d2 <= d5 Then 'ugovor do
c2 = d2
ElseIf d2 > d5 And Month(d2) = Month(d5) Then
c2 = d5
Else
c2 = 0
End If
If d1 >= d4 And d1 <= d6 Then 'anex OD
c3 = d1
ElseIf d1 < d4 And Month(d1) = Month(d4) Then
c3 = d4
Else
c3 = 0
End If
If d2 >= d4 And d2 <= d6 Then 'anex do
c4 = d2
ElseIf d2 > d6 And Month(d2) = Month(d6) Then
c4 = d6
Else
c4 = 0
End If
If c1 <= c3 Then
b1 = c3
b3 = ISO_WorkdayDiff(c1, c3, True) + ISO_WorkdayDiff(c4, c2, True)
Else
b1 = c1
b3 = ISO_WorkdayDiff(c1, d2, True)
End If
If c4 <= c2 Then
b2 = c2
b4 = ISO_WorkdayDiff(c3, c4, True)
Else
b2 = c4
b4 = ISO_WorkdayDiff(c3, d2, True)
End If
b5 = ISO_WorkdayDiff(DateSerial(Year(b2), Month(b2), 1), DateSerial(Year(b2), Month(b2) + 1, 1), True)
a1 = Me.Text550.Value * 800 * b4/b5
a2 = d7 * d8
a3 = d9 * d10
a4 = a3 * Text550.Value
a5 = Me.Text608.Value * b3/b5
a6 = (a2 - a5 * Me.Text566.Value)/(1 - Me.Text566.Value - Me.Text573.Value - Me.Text575.Value - Me.Text570.Value)
a7 = (a6 - a5) * Me.Text566.Value
a8 = a6 * Me.Text570.Value
a9 = a6 * Me.Text575.Value
a10 = a6 * Me.Text573.Value
a11 = a6 * Me.Text589.Value
a12 = a6 * Me.Text591.Value
a13 = a6 * Me.Text593.Value
a14 = a6 + a6 * (Me.Text593.Value + Me.Text591.Value + Me.Text589.Value)
a15 = Me.Text833.Value * b4/b5
a16 = (a1 - a15) * Me.Text566.Value
a17 = a1 * Me.Text570.Value
a18 = a1 * Me.Text575.Value
a19 = a1 * Me.Text573.Value
a20 = a1 * Me.Text589.Value
a21 = a1 * Me.Text591.Value
a22 = a1 * Me.Text593.Value
a23 = a1 + a1 * (Me.Text593.Value + Me.Text591.Value + Me.Text589.Value)
rs!Broj_dana_u_SRB = b3
rs!Broj_dana_u_INO = b4
rs!Obracun_Plate_OD = b1
rs!Obracun_Plate_DO = b2
rs!Ukp_Broj_Radnih_dana_u_mjes = b5
rs!Kurs = Me.Text550.Value
rs!Neto_Plata_SRB = a2
rs!Neto_Plata_INO = a3
rs!Neto_Plata_INO_RSD = a4
rs!Poresko_Oslobodjenje_SRB = a5
rs!Bruto_Plata_SRB = a6
rs!Poreska_stopa_SRB = a7
rs!Doprinosi_SRB_Zaposleni_PIO = a8
rs!Doprinosi_SRB_Zaposleni_Zdravstvo = a9
rs!Doprinosi_SRB_Zaposleni_NeZaposlenost = a10
rs!Doprinosi_SRB_Poslodavac_PIO = a11
rs!Doprinosi_SRB_Poslodavac_Zdravstvo = a12
rs!Doprinosi_SRB_Poslodavac_NeZaposlenost = a13
rs!Ukupni_troskovi_plate_SRB = a14
rs!Poresko_Oslobodjenje_INO = a15
rs!Bruto_Plata_INO = a1
rs!Poreska_stopa_INO = a16
rs!Doprinosi_INO_Zaposleni_PIO = a17
rs!Doprinosi_INO_Zaposleni_Zdravstvo = a18
rs!Doprinosi_INO_Zaposleni_NeZaposlenost = a19
rs!Doprinosi_INO_Poslodavac_PIO = a20
rs!Doprinosi_INO_Poslodavac_Zdravstvo = a21
rs!Doprinosi_INO_Poslodavac_NeZaposlenost = a22
rs!Ukupni_troskovi_plate_INO = a23
rs.Update
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
SQL代碼,相同的結果,重複值的所有行
DoCmd.RunSQL "UPDATE contacts SET [Broj_dana_u_SRB] = " & b3
DoCmd.RunSQL "UPDATE contacts SET [Broj_dana_u_INO] = " & b4
DoCmd.RunSQL "UPDATE contacts SET [Obracun_Plate_OD] = " & b1
DoCmd.RunSQL "UPDATE contacts SET [Obracun_Plate_DO] = " & b2
DoCmd.RunSQL "UPDATE contacts SET [Ukp_Broj_Radnih_dana_u_mjes] = " & b5
DoCmd.RunSQL "UPDATE contacts SET [Kurs] = " & Me.Text550.Value
DoCmd.RunSQL "UPDATE contacts SET [Neto_Plata_SRB] = " & a2
DoCmd.RunSQL "UPDATE contacts SET [Neto_Plata_INO] = " & a3
DoCmd.RunSQL "UPDATE contacts SET [Neto_Plata_INO_RSD] = " & a4
DoCmd.RunSQL "UPDATE contacts SET [Poresko_Oslobodjenje_SRB] = " & a5
DoCmd.RunSQL "UPDATE contacts SET [Bruto_Plata_SRB] = " & a6
DoCmd.RunSQL "UPDATE contacts SET [Poreska_stopa_SRB] = " & a7
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_SRB_Zaposleni_PIO] = " & a8
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_SRB_Zaposleni_Zdravstvo] = " & a9
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_SRB_Zaposleni_NeZaposlenost] = " & a10
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_SRB_Poslodavac_PIO] = " & a11
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_SRB_Poslodavac_Zdravstvo] = " & a12
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_SRB_Poslodavac_NeZaposlenost] = " & a13
DoCmd.RunSQL "UPDATE contacts SET [Ukupni_troskovi_plate_SRB] = " & a14
DoCmd.RunSQL "UPDATE contacts SET [Poresko_Oslobodjenje_INO] = " & a15
DoCmd.RunSQL "UPDATE contacts SET [Bruto_Plata_INO] = " & a1
DoCmd.RunSQL "UPDATE contacts SET [Poreska_stopa_INO] = " & a16
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_INO_Zaposleni_PIO] = " & a17
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_INO_Zaposleni_Zdravstvo] = " & a18
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_INO_Zaposleni_NeZaposlenost] = " & a19
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_INO_Poslodavac_PIO] = " & a20
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_INO_Poslodavac_Zdravstvo] = " & a21
DoCmd.RunSQL "UPDATE contacts SET [Doprinosi_INO_Poslodavac_NeZaposlenost] = " & a22
DoCmd.RunSQL "UPDATE contacts SET [Ukupni_troskovi_plate_INO] = " & a23
變量引用將它基於表單輸入來編寫SQL更容易嗎? –
我會嘗試寫它 – Neso
隨着SQL我得到了相同的結果,在所有行中重複的數據 – Neso