Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

How format numbers differently in a listbox

Posted on 2014-04-26
Medium Priority
515 Views
I have this SQL code in a query which drops the decimals from the number which is exactly what I want to do:

SELECT tblEstParts.EstPartID, tblEstParts.PartDesc, tblPaper.Description, tblEstParts.InkColors, Format([tblEstParts].[Qty1],"0") AS [Qty 1], Format([tblEstParts].[Qty2],"0") AS [Qty 2], Format([tblEstParts].[Qty3],"0") AS [Qty 3], Format([tblEstParts].[Qty4],"0") AS [Qty 4], Format([tblEstParts].[Qty5],"0") AS [Qty 5]
FROM tblEstParts LEFT JOIN tblPaper ON tblEstParts.PaperID = tblPaper.PaperID
ORDER BY tblEstParts.PartDesc;

But I also want the numbers to have a comma if for example the number is 2500 I want the listbox field to display 2,500

How can this be done?

--Steve
0
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 120

Assisted Solution

Rey Obrero (Capricorn1) earned 1000 total points
ID: 40024620
try something like this

Format([tblEstParts].[Qty3],"#,###")
0

LVL 48

Accepted Solution

Dale Fye earned 1000 total points
ID: 40024735
Actually, all values in a listbox are formatted like text, so if you want the numbers to align to the right side of a column, you will have to set the font to a non-proportional font (I like Consolas, but Courier New works too), and will then need to pad the string to however many characters you want.  So try something like:

Right(Space(8) & Format([tblEstParts].Qty3, "#,###"), 8)

HTH

Dale
0

LVL 19

Expert Comment

ID: 40024932

The "0" in use means that at least one numerical character will be displayed with no decimal place.

The "#,##0" means that additional places can be displayed add the thousands separator (",") and still no decimal places.

Since you are  using this on a numeric field, I don't think the text comment applies.  The field should stay numeric.  Please correct me if I am wrong.  The listbox that this populates is written in with what language?   Some languages have separate listbox properties for alignment.
0

LVL 51

Expert Comment

ID: 40025580
List- and comboboxes always display text, thus numbers will be left aligned.
Further, the output from Format is text, so even if numbers were right aligned it wouldn't make a difference.

/gustav
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses
Course of the Month7 days, 8 hours left to enroll