J
Jesse Aviles
I have the following function:
Function GetCurrentBalance() As Currency
Dim db As Database
Dim rstRegister As Recordset
Dim strSQL As String
'The lng variables contain the AbsolutePosition of the record
Dim lngMyPosition As Long, lngRecPosition As Long
Dim curRecordBalance As Currency, curPayments As Currency, curDeposits As
Currency
On Error GoTo ErrorHandler
Set db = CurrentDb
strSQL = "SELECT * FROM Register"
Set rstRegister = db.OpenRecordset(strSQL, dbOpenDynaset)
'Set the value of the current record to the variables
lngMyPosition = rstRegister.AbsolutePosition
lngRecPosition = rstRegister.AbsolutePosition
If lngMyPosition = -1 Then
GoTo Exit_GetCurrentBalance
Else
curPayments = DSum("Payments", rstRegister, "Void <> True And
MyPosition <= lngRecordPosition")
curDeposits = DSum("Deposits", rstRegister, "MyPosition <=
lngRecordPosition")
curRecordBalance = curDeposits - curPayments
Balance = curRecordBalance
End If
GoTo Exit_GetCurrentBalance
Exit_GetCurrentBalance:
Set rstRegister = Nothing
Set db = Nothing
Exit Function
ErrorHandler:
MsgBox "Error Number: " & Err.Number & vbCrLf & Err.Description, ,
"Function Error"
GoTo Exit_GetCurrentBalance
End Function
When I decompile the functions it says Type Mismatch and highlights DSum. I
have a form that works as check register with an unbound textbox that shows
the current balance using the following string
=DSum("0+Nz([DepositAmnt])-Nz([PaymentAmnt])","TrnxRegister"," [TrnxNo] <=
[Forms]![Register]![TrnxNo] and Void <> True")
It works fine except that TrnxNo is not necessarily arranged by date. If I
arrange the form by date, I may not be seeing the current balance. I tried
using the .AbsolutePosition property since it will generate a unique number
based on the current sort order (so I can sort by date, check number or
payee). I wanted to add this function to the unbound text box but the
function is not working. Any help?
Function GetCurrentBalance() As Currency
Dim db As Database
Dim rstRegister As Recordset
Dim strSQL As String
'The lng variables contain the AbsolutePosition of the record
Dim lngMyPosition As Long, lngRecPosition As Long
Dim curRecordBalance As Currency, curPayments As Currency, curDeposits As
Currency
On Error GoTo ErrorHandler
Set db = CurrentDb
strSQL = "SELECT * FROM Register"
Set rstRegister = db.OpenRecordset(strSQL, dbOpenDynaset)
'Set the value of the current record to the variables
lngMyPosition = rstRegister.AbsolutePosition
lngRecPosition = rstRegister.AbsolutePosition
If lngMyPosition = -1 Then
GoTo Exit_GetCurrentBalance
Else
curPayments = DSum("Payments", rstRegister, "Void <> True And
MyPosition <= lngRecordPosition")
curDeposits = DSum("Deposits", rstRegister, "MyPosition <=
lngRecordPosition")
curRecordBalance = curDeposits - curPayments
Balance = curRecordBalance
End If
GoTo Exit_GetCurrentBalance
Exit_GetCurrentBalance:
Set rstRegister = Nothing
Set db = Nothing
Exit Function
ErrorHandler:
MsgBox "Error Number: " & Err.Number & vbCrLf & Err.Description, ,
"Function Error"
GoTo Exit_GetCurrentBalance
End Function
When I decompile the functions it says Type Mismatch and highlights DSum. I
have a form that works as check register with an unbound textbox that shows
the current balance using the following string
=DSum("0+Nz([DepositAmnt])-Nz([PaymentAmnt])","TrnxRegister"," [TrnxNo] <=
[Forms]![Register]![TrnxNo] and Void <> True")
It works fine except that TrnxNo is not necessarily arranged by date. If I
arrange the form by date, I may not be seeing the current balance. I tried
using the .AbsolutePosition property since it will generate a unique number
based on the current sort order (so I can sort by date, check number or
payee). I wanted to add this function to the unbound text box but the
function is not working. Any help?