Hi, i'm trying to count the numbers between 60001 and 60061 with dcount and put the result in a text box, but all i get is an error, this is the code i'm using .... =DCount("*","[ALL]","[AddNumber] >= 60001 And [AddNumber] <= 60061")
you're right, the addnumber type was short text, let me explain further, the table consists of numbers from 03001 to 89500, which is why i had to put the type as short text, so it would except the numbers starting with a '0', is there a way of writing the code so it works with numbers starting with '0'?AddNumber is a number type field?
What circumstances would return a result other than 60?
SELECT * FROM ALL WHERE [AddNumber] >= 60001 AND [AddNumber] <= 60061 ;
DCount normally doesn't care about nulls (just ignores them). The arguments are a field (or * ), a record source, and 0 or more criteria.
Usually, "*" is valid in that position. For snorts and giggles, you MIGHT try "[AddNumber]" in place of the "*" - though I'm not betting on that.
Don't know your tables, but if [ALL] is a valid table name or a validly named SELECT query, you should be OK.
That leaves the criteria. The only way that would fail is if [AddNumber] isn't really a number OR if there is a hidden, non-printing character in the mix.
You might try to create a query to see what it returns:
Code:SELECT * FROM ALL WHERE [AddNumber] >= 60001 AND [AddNumber] <= 60061 ;
they are to be primarily treated as numbers, the reason they are text is so they display in a text box as they are in typed in the table, if i change the field type to number, it deletes the leading zeroYour post crossed mine in posting. The real question is why those numbers have leading zeros. Your problem has nothing to do with accepting numbers with leading zeros. When you have the numbers in a table, are they to be primarily treated as numbers or primarily treated as strings that happen to look like numbers? The display format for those numbers can be controlled with a Format function. But why are they text? (NOTE: Access would correctly handle numbers with leading zeroes for input.)
I've tried both yours and june7 codes and they work upto a point, but they are not counting the numbers with a leading zero. i changed the format to '00000' on the numbers field but it did'nt make any differenceAh, but if you then decide to use the FORMAT function, you can put as many leading zeros as you want for display purposes, because remember that Access doesn't care what you put in a text box. It's just a display artifice. If you use the raw number, you get... the raw number. If you use FORMAT( n, "000000" ) you get a number with leading zeros. OR better yet, you can diddle with the text box's FORMAT property to the same effect. So instead of displaying raw numbers, display formatted numbers. Computers can do that for you.
Well TBH, if they had to be numbers, they would be numeric in my db, then all this is moot.Val() is definitely an option.
All i get is an #Name? in the text box
this thread seems to be circling the drain.is there a way of writing the code so it works with numbers starting with '0'?