Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Summing List Box from in Text Box WIth Data Type Error

Status
Not open for further replies.

Fattire

Technical User
Nov 30, 2006
127
US
I use this code to sum up column 9 into a list box whenever its requeried but if there isn't at least a $0.00 in the column it says I have a data type problem. It's hung up on the NULL's. The data type in the table the value is held is set to currency. I've tried NZ, I've tried Format, IsNull() but nothing seems to work. Messes up on the line:
Code:
listsum4 = listsum4 + (Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x))
Any help would be aprpeciated:

Code:
Public Function AMTCOLLECTED()
    
    Dim listrs4 As Single
    Dim listsum4 As Single
    
    listrs4 = Forms!FRM_MAIN!LST_OPEN_BALANCES.ListCount
    If listrs4 = "0" Then
    Forms!FRM_MAIN!TXT_AMT_COLLECTED.Value = "0"
    Else
    x = 1
    Do
    listsum4 = listsum4 + (Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x))
    x = x + 1
    Loop Until x = listrs4
    Forms!FRM_MAIN!TXT_AMT_COLLECTED.Value = listsum4
    
    End If
    
End Function
 
And yes "On Error Resume Next" works... but I just hate using that. But if that's what I need to do then... so be it.

 
dhookom - being single it should, 0 erred out, "0" does not for some reason.

Hap007 - conversion function - excellent idea, never thought of that CSng but it gave me the error 13 type mismatch unfortunately, tried the CDbl and CCur as well, no luck

Ahhh... just tried Val - that worked... thanks for the direction - I'm going to try and get rid of that first if statement now.

Here's the line:
Code:
listsum4 = listsum4 + Val(Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x))
 
The list box is populated by a query. The table the query comes from for column(9) has a data type of Currency, the query for column 9 has no format properties. Not sure where the variant comes into play though.

btw... Val stopped working after I did a compact and repair, so I recently went back to 'On Error Resume Next'

I tried these:
NZ(Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x)), 0)
NZ(Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x)), "0")
CDbl(NZ(Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x))
CCur(Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x))
CSng(Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x))
Val(Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x))

I think there may be some conflict with the expression I'm using for calculating column 9: I lost the formatting with the space function so I forced it in there, but the space or right may be messing it up as well:

Code:
Amt Collected: Right(Space(13) & Format([APPLIED_AMOUNT],"$#,###.00"),13)
 
What about this ?
listsum4 = listsum4 + Val(Replace(Replace(Forms!FRM_MAIN!LST_OPEN_BALANCES.Column(9, x), "$", ""), ",", ""))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
When all else fails, I would do something like this
Dim tempValue as Single
Dim tempFld as string

then...
tempValue = 0
tempFld = Trim(Forms!FRM_MAIN!LST_OPEN_BALANCES.column(9, x) & " ")
If Len(tempFld)>0 Then
tempValue = Val(TempFld)
End If

listsum4 = listsum4 + tempValue


I know it is ugly code, but the Trim and Len should keep always work.

Hap...

Access Developer [pc] Access based Accounting Solutions - with free source code
Access Consultants forum
 
PHV - That works, and makes sense now... took the resume next out and it still works -

Hap007 I stuck your code in one of the columns it also does not error, thanks.
 
Just a suggestion,

It sounds like the formatting was getting in the way.

In the past, I have created extra columns in the list box and set their width to zero.

Then, I can store unformated data in those hidden columns for later use.

This works great when storing key valuse and the like.

If you had stored the unformated amounts in a hidden column, you might never had this problem in the first place.

Just my 2 cents, Enjoy,
Hap...

Access Developer [pc] Access based Accounting Solutions - with free source code
Access Consultants forum
 
By the way I had to change the data type in the module to Double; Single was causing a .03 variation every $150,000 in the totals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top