J
Jesse Aviles
I have the following Private function within a form module:
Private Function CalculateBalance() As Currency
Dim rst As DAO.Recordset
Dim frm As Form
Dim lngMyPosition As Long
Dim curSumPayments As Currency
Dim curSumDeposits As Currency
On Error GoTo HandleErrors
Set frm = Me
Set rst = frm.RecordsetClone
With rst
.MoveLast
.MoveFirst
End With
rst.Bookmark = frm.Bookmark
lngMyPosition = rst.AbsolutePosition
Debug.Print "lngMyPosition: " & lngMyPosition
curSumPayments = DSum("0 + Nz([curPayment])", "tblTrnxRegister", _
"lulngBankAccountID= " & frm!cboAccountSelector And frm!bolVoid =
False And _
rst.AbsolutePosition <= lngMyPosition And rst.EOF = False)
Debug.Print "curSumPayments: " & curSumPayments
curSumDeposits = DSum("0 + Nz[curDeposit]", "tblTrnxRegister", _
"lulngBankAccountID= " & frm!cboAccountSelector And _
rst.AbsolutePosition <= lngMyPosition And rst.EOF = False)
Debug.Print "curSumDeposits: " & curSumDeposits
CalculateBalance = CCur(curSumDeposits - curSumPayments)
Debug.Print "CalculateBalance: " & CalculateBalance
ExitHandler:
Set rst = Nothing
Exit Function
HandleErrors:
Select Case Err.Number
Case 3021
Resume Next
Case Else
MsgBox "Error number: " & Err.Number & vbCrLf & vbCrLf &
Err.Description, vbMsgBoxHelpButton, "Unexpected error", Err.HelpFile,
Err.HelpContext
GoTo ExitHandler
End Select
End Function
The function gets called from a control with its format property set to
currency and I get an error 13, Type mismatch. Variables, fields and the
function are set as currency. The code appears to stop at the - Debug.Print
"lngMyPosition: " & lngMyPosition - statement since that is the only value I
can see in the Immediate window. I also set the code to ignore the error to
see what values I was getting from the calculations and VBA is not
evaluating the formulas (value received is 0). I've checked the names of
the fields and tables and they are correct. Thanks for any help.
Private Function CalculateBalance() As Currency
Dim rst As DAO.Recordset
Dim frm As Form
Dim lngMyPosition As Long
Dim curSumPayments As Currency
Dim curSumDeposits As Currency
On Error GoTo HandleErrors
Set frm = Me
Set rst = frm.RecordsetClone
With rst
.MoveLast
.MoveFirst
End With
rst.Bookmark = frm.Bookmark
lngMyPosition = rst.AbsolutePosition
Debug.Print "lngMyPosition: " & lngMyPosition
curSumPayments = DSum("0 + Nz([curPayment])", "tblTrnxRegister", _
"lulngBankAccountID= " & frm!cboAccountSelector And frm!bolVoid =
False And _
rst.AbsolutePosition <= lngMyPosition And rst.EOF = False)
Debug.Print "curSumPayments: " & curSumPayments
curSumDeposits = DSum("0 + Nz[curDeposit]", "tblTrnxRegister", _
"lulngBankAccountID= " & frm!cboAccountSelector And _
rst.AbsolutePosition <= lngMyPosition And rst.EOF = False)
Debug.Print "curSumDeposits: " & curSumDeposits
CalculateBalance = CCur(curSumDeposits - curSumPayments)
Debug.Print "CalculateBalance: " & CalculateBalance
ExitHandler:
Set rst = Nothing
Exit Function
HandleErrors:
Select Case Err.Number
Case 3021
Resume Next
Case Else
MsgBox "Error number: " & Err.Number & vbCrLf & vbCrLf &
Err.Description, vbMsgBoxHelpButton, "Unexpected error", Err.HelpFile,
Err.HelpContext
GoTo ExitHandler
End Select
End Function
The function gets called from a control with its format property set to
currency and I get an error 13, Type mismatch. Variables, fields and the
function are set as currency. The code appears to stop at the - Debug.Print
"lngMyPosition: " & lngMyPosition - statement since that is the only value I
can see in the Immediate window. I also set the code to ignore the error to
see what values I was getting from the calculations and VBA is not
evaluating the formulas (value received is 0). I've checked the names of
the fields and tables and they are correct. Thanks for any help.