arnelgp
..forever waiting... waiting for jellybean!
- Local time
- Today, 21:40
- Joined
- May 7, 2009
- Messages
- 19,836
yes, so i edited by post.Just a personal preference.
yes, so i edited by post.Just a personal preference.
With a large number of records in the table, your code faces a performance problem because it opens the recordset (RS.RecordCount - 1) times.yes, so i edited by post.
Public RS As DAO.Recordset
Public Function fnBalance(ByVal ID As Long) As Double
Dim result As Double
If RS Is Nothing Then
Set RS = CurrentDb.OpenRecordset("SELECT * FROM tblChecking ORDER BY TransDate, ID;", dbOpenSnapshot, dbReadOnly)
End If
With RS
...... ---> Do calculations
End With
fnBalance = result
End Function
Private Sub Form_Open(Cancel As Integer)
Set RS = Nothing
End Sub
Public Function fnBalance(ByVal ID As Long) As Double
' ID can be:
' -1 release the recordset
' 0 requery the recordset
' any number the actual id number
Static rs As DAO.Recordset 'rs is preserved when the db is open and will be closed automatically when you the db
Dim result As Double
If ID = -1 Then
If Not (rs Is Nothing) Then
rs.Close
Set rs = Nothing
Exit Function
End If
End If
If rs Is Nothing Then
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblChecking ORDER BY TransDate, ID;", dbOpenSnapshot, dbReadOnly)
End If
If ID = 0 Then
rs.Requery
Exit Function
End If
With rs
.FindFirst "ID = " & ID
Do Until .BOF
result = result + Nz(!Credit, 0) - Nz(!Debit, 0)
.MovePrevious
Loop
End With
fnBalance = result
End Function
The NEXT button on the main form?Use the Account in the criteria?
Ok thanksNo you include the account in the dsum criteria. That should start at zero for the very first record for that account, if you also check for account.
=Val(DSum("Nz(Debit,0)-Nz(Credit,0)","qryCheckRegister","[Account] = '" & [Forms]![frmBankAccounts]![Account] & "'" And "ID<=" & [ID]))
already mentioned this won't work if there are "Late" entries on the transactions.=Val(DSum("Nz(Debit,0)-Nz(Credit,0)","qryCheckRegister","[Account] = '" & _
[Forms]![frmBankAccounts]![Account] & "' And ID <= " & [ID]))
Thanks but I did try it without the quotes before ID (at least I think I did)=Val(DSum("Nz(Debit,0)-Nz(Credit,0)","qryCheckRegister","[Account] = '" & _
[Forms]![frmBankAccounts]![Account] & "' And ID <= " & [ID]))
Imported by QuickBooks that way. I would have to convert it to use an autonumberI would have hoped that Account would be an autonumber
Fair enough.Imported by QuickBooks that way. I would have to convert it to use an autonumber
No.Thanks but isn't that the same?
=Val(DSum("Nz(Debit,0)-Nz(Credit,0)","qryCheckRegister","[Account] = '" & [Forms]![frmBankAccounts]![Account] & "'" And "ID & =" & [ID]))
=Val(DSum("Nz(Debit,0)-Nz(Credit,0)","qryCheckRegister","[Account] = '" & [Forms]![frmBankAccounts]![Account] & "' And ID <= " & [ID]))
I get #Error on this.No.
Yours then Duanes
Code:=Val(DSum("Nz(Debit,0)-Nz(Credit,0)","qryCheckRegister","[Account] = '" & [Forms]![frmBankAccounts]![Account] & "'" And "ID & =" & [ID])) =Val(DSum("Nz(Debit,0)-Nz(Credit,0)","qryCheckRegister","[Account] = '" & [Forms]![frmBankAccounts]![Account] & "' And ID <= " & [ID]))
Did you get the same error using Duane's version?I get #Error on this.
I used Duane's version. My version gave the same amount on each recordDid you get the same error using Duane's version?