changing number formats in VBA

  • Thread starter Thread starter John Milward
  • Start date Start date
J

John Milward

Hi

I have created a report which prints tables of numbers.
I need to change the number of decimal places shown for each table
I have an additional field (txtRes) that specifies the number of decimal
places

I have tried the following code in Detail_Format & Detail_Print

Select Case txtRes
Case 0.1
Me.txtResult.DecimalPlaces = 1
Case 0.01
Me.txtResult.DecimalPlaces = 2
Case Else
Me.txtResult.DecimalPlaces = 0
End Select

The case statement is responding to txtres, but the statement
Me.txtResult.DecimalPlaces = ? does nothing

The design properties for txtResult are set to fixed Format and Decimal
places = 0

Any help would be appreciated

TIA

John
 
The DecimalPlaces property to limit the maximum number of decimals
displayed, it won't give you trailing zeros. If that is what you need, then
you'll need to adjust the Format property of the textbox also.

Select Case txtRes
Case 0.1
Me.txtResult.DecimalPlaces = 1
Me.txtResult.Format = "0.0"
Case 0.01
Me.txtResult.DecimalPlaces = 2
Me.txtResult.Format = "0.00"
Case Else
Me.txtResult.DecimalPlaces = 0
End Select

If you want commas in for separators also, you'll need to expand the format.

Me.txtREsult.Format = "#,##0.00"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top