special format number

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

special format number

Post by sal21 »

Actually i format this rs1 with:

Format(RS1.Fields(7).Value, "#,##0.00")

if the value of rs1 is 0 i have 0,00

but i need this new format:

000.000,00

how to?

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: special format number

Post by Rudi »

You could try using an IF statement.

If RS1.Fields(7).Value > 0 then
Format(RS1.Fields(7).Value, "#,##0.00")
ElseIf RS1.Fields(7).Value = 0
Format(RS1.Fields(7).Value, "000,000.00")
End If
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78420
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: special format number

Post by HansV »

Or even

Code: Select all

    If RS1.Fields(7).Value > 0 then 
        MyVar = Format(RS1.Fields(7).Value, "#,##0.00")
    ElseIf RS1.Fields(7).Value = 0
        MyVar = "000,000.00"
    End If
Best wishes,
Hans

PJ_in_FL
5StarLounger
Posts: 1098
Joined: 21 Jan 2011, 16:51
Location: Florida

Re: special format number

Post by PJ_in_FL »

What Office application is this in? If Excel, you can skip all the If statements and apply custom formatting directly to the cell.

The Excel custom format is capable of applying formatting based on values <0, >0 and =0.

From Excel's Help:
A number format can have up to four sections of code, separated by semicolons. These code sections define the format for positive numbers, negative numbers, zero values, and text, in that order.

<POSITIVE>;<NEGATIVE>;<ZERO>;<TEXT>
If you're trying to format data in VBA for a cell in Excel, let Excel do the formatting with the custom format of:

Code: Select all

#,##0.00;;"000,000.00"
which will use your format for any positive number and the string "000,000.00" for any cell = 0.
PJ in (usually sunny) FL