This is the first time I'm setting up my own loop code. What I'm trying to do with this form is create a check register that adds up the deposits and payments. I was able to make this code work in the debug window using the recordset of the underlying table. My challenge is occuring when I'm trying to make it work in the form:
Public Function LoopRecordset()
Dim db As Database, rst As Recordset, intb As Long
Set db = DBEngine(0)(0)
Set rst = db.OpenRecordset("frm", dbOpenForm) ' This is where the errors occuring.
Do Until rst.EOF
If IsNull(rst!txtPayment) Then
intb = intb + rst!txtDeposit
Forms!frm!txtBalance = intb
rst.MoveNext
Else
intb = intb - rst!txtPayment
Forms!frm!txtBalance = intb
rst.MoveNext
End If
Loop
End Function
I know I've set the rst variable wrong but don't know how to correct it.
Suggestions
Public Function LoopRecordset()
Dim db As Database, rst As Recordset, intb As Long
Set db = DBEngine(0)(0)
Set rst = db.OpenRecordset("frm", dbOpenForm) ' This is where the errors occuring.
Do Until rst.EOF
If IsNull(rst!txtPayment) Then
intb = intb + rst!txtDeposit
Forms!frm!txtBalance = intb
rst.MoveNext
Else
intb = intb - rst!txtPayment
Forms!frm!txtBalance = intb
rst.MoveNext
End If
Loop
End Function
I know I've set the rst variable wrong but don't know how to correct it.
Suggestions