views:

183

answers:

2

So I have a list box that displays averages in a table like format from a crossyab query. It's just what I need the query is right, there is just one thing. I had to set the field properties in the query as format: standard..decimal:2. Which is exactly what I needed. However..the list box will not pick up on this.

First I typed the crosstab sql into the list box's properties....and then I ran into this problem. So then I actually just created the query object, saved it and set that as the rowsource for the list box. Still won't work....when I open the query it is the correct format.

So is there a way to further format a text box? Is there a way tell it to limit decimal places to one or two on returned values?

Thanks!

+2  A: 

Try the Format function in your query to transform your numerical values to formatted strings. Here is a sample I copied from the Immediate Window:

? Format(-.2345,"###,###,##0.##")
-0.23

Edit: Here is an example using the Format function in a query.

SELECT Format(num_field, "###,###,##0.##") AS two_decimals
FROM MyTable;

Try a similar approach using your saved crosstab query in place of MyTable.

HansUp
ok though I am uncertain about what I should enter into the format field from example?? should i enter everything in paren?
Justin
@Justin I hope the edit made it clear. If not, let me know.
HansUp
Oh yeah. Thanks that is awesome!
Justin
A: 

Your listbox object has a Format property of it's own. I would suggest entering "#,###.##". This will display the data with a comma (if needed) and 2 decimal places.

EDIT: Whoops. I was thinking of a ComboBox control, not a ListBox Control. By way of apology, please accept a 20% discount off this advice.

PowerUser
@PowerUser Where do you find a format property for a *listbox* control? A textbox control has a format property, but I can't find it for a listbox.
HansUp
Whoops. See my Edit above.
PowerUser
@PowerUser In that case, how can you add your suggested format string to the Format property of a combobox? Even if it can be done, it appears the formatting would only be applied to the selected value of the bound column --- the values in the drop down list receive the same number of decimal places as the underlying RowSource.
HansUp