listbox formatting

  • Thread starter Thread starter drabbacs
  • Start date Start date
D

drabbacs

I want to know how to specify display formatting in
several listboxes. Specifically I want red and parenthesis
if a value is negative, percentages instead of decimals,
and a limitation on the number of decimal places that are
displayed; 25.1% not .251345987.

The row sources for the list boxes are tables and queries
which are updated/refreshed/overwritten each time the user
visits this form. Conditional formatting is not accesible
via the format menu for listboxes.

How does one set these type of formatting requirements for
objects that essentially do not exist prior to opening the
form? I'm thinking there must be some VB code which would
allow me to set the formats. What would that code look
like? Would it be accessed from the macro which opens the
form and runs the queries necessary to populate the list
boxes?

Thanks for any help.
Drabbacs
 
drabbacs said:
I want to know how to specify display formatting in
several listboxes. Specifically I want red and parenthesis
if a value is negative, percentages instead of decimals,
and a limitation on the number of decimal places that are
displayed; 25.1% not .251345987.

The row sources for the list boxes are tables and queries
which are updated/refreshed/overwritten each time the user
visits this form. Conditional formatting is not accesible
via the format menu for listboxes.

How does one set these type of formatting requirements for
objects that essentially do not exist prior to opening the
form? I'm thinking there must be some VB code which would
allow me to set the formats. What would that code look
like? Would it be accessed from the macro which opens the
form and runs the queries necessary to populate the list
boxes?

Thanks for any help.
Drabbacs

You can do the string formatting -- negatives as parentheses, percent
formatting, number of decimal places -- by using a query as the
rowsource of your list box and letting the query apply the Format
function to the raw data. For example,

SELECT Format(SomeFraction, "0.0%;(0.0%)") As PctVal
FROM MyTable;

However, as far as I know you can't get color-highlighting in a list
box. You *could* add a special column to the rowsource to highlight the
fact that this item is negative:

SELECT
Format(SomeFraction, "0.0%;(0.0%)") As PctVal,
IIf(SomeFraction < 0, "", "<-- Look!") As Lookie
FROM MyTable;

Or depending on your circumstances you could make your list box be
multiselect and have code that loops through the list items after it's
loaded, selecting (and thus highlighting) those entries that have
negative values.
 
-----Original Message-----


You can do the string formatting -- negatives as parentheses, percent
formatting, number of decimal places -- by using a query as the
rowsource of your list box and letting the query apply the Format
function to the raw data. For example,

SELECT Format(SomeFraction, "0.0%;(0.0%)") As PctVal
FROM MyTable;

However, as far as I know you can't get color-highlighting in a list
box. You *could* add a special column to the rowsource to highlight the
fact that this item is negative:

SELECT
Format(SomeFraction, "0.0%;(0.0%)") As PctVal,
IIf(SomeFraction < 0, "", "<-- Look!") As Lookie
FROM MyTable;

Or depending on your circumstances you could make your list box be
multiselect and have code that loops through the list items after it's
loaded, selecting (and thus highlighting) those entries that have
negative values.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.

Here's some code that shows how to do custom (color)
formatting in a list box. Looks like its operating on
whole rows, however, not particular fields within rows.

http://www.lebans.com/listboxenhanced.htm

- J.D.
 
Back
Top