So it sounds like you have this:
tblIbbMstr
ob
recmth
recamt
And you want to take an entry from this table, for example:
ob - 1000
ecmth - 01/01/2007
recamt - 200
And post it to a new table:
tbl???
ob
recmnth
recamt
cb
until the account i zeroed out. Is that correct?
If so:
Dim rs1, rs2 As ADODB.Recordset
Dim sSQL1, sSQL2 As String
Dim iPK, i As Integer 'Primary key from your form?
Dim l_Ob, l_cb As Long
Dim dtRecmth As Date
iPK = Me.PKID
'Open recordset on source table
sSQL1 = "SELECT * FROM tblIbbMstr WHERE [PKID] = " & iPK
Set rs1 = New ADODB.Recordset
rs1.Open sSQL1, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
'Open recordset on target table
sSQL2 = "SELECT * FROM tbl???"
Set rs2 = New ADODB.Recordset
rs2.Open sSQL2, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If rs1.Recordcount <> 0 Then
l_Ob = rs1("ob")
dtRecmth = rs1("recmth")
l_amt = rs1("recamt")
l_cb = l_Ob - l_amt
Else
MsgBox "No record", vbCritical
Exit Sub
End If
i = 1
Do Until l_Ob = 0 Or i = 100
rs2.AddNew
rs2("ob") = l_Ob
rs2("recmnth") = dtRecmth
rs2("recamt") = rs1("recamt")
rs2("cb") = l_Ob - rs1("recamt")
rs2.Update
dtRecmth = DateAdd("m", 1, dtRecmth)
l_Ob = l_Ob - l_amt
l_cb = l_cb - l_amt
i = i + 1
Loop
That should get you there in ADO. I only do ADO since I usually only do Access/SQL, but the flow control should work for DAO if that is what you are using.
You also probably want to add the PK to the target table to know what record is subtends from.
Here is the flow control in a VBScript to test. I use the i counter to prevent the loop from running away, but you may need more than 100 iterations.
l_Ob = CInt(1000)
Recmth = Date()
l_amt = CInt(200)
l_cb = l_ob - l_amt
i = 1
Do Until l_Ob = 0 Or i = 10
WScript.Echo l_Ob & ", " & Recmth & ", " & l_amt & ", " & l_cb
Recmth = DateAdd("m", 1, dtRecmth)
l_cb = l_cb - l_amt
l_Ob = l_Ob - l_amt
i = i + 1
Loop
Did this work?
mmcdonal
|