On Sep 20, 7:18 pm, "Mark G." <anon40...@hotmail.comwrote:
Good afternoon.
I have a "Fixed/2" format applied to a textbox on its property sheet. When I
type data in the textbox, it is formatted correctly. But when I update the
value programatically by setting the "value" property, the text does not
format.
I can get around this of course by using the VBA format() command. But is
there any way I could update the value in code and have it display according
to the format that is specified on the control's property sheet?
Thanks
-Mark
The following brute force ugly HACK might help:
....
Dim varNewValue As Variant
Dim strIn As String
varNewValue = 24.3333
If MyTextbox.Format = "Fixed" Then
If MyTextbox.DecimalPlaces = 255 Then
'Auto
strIn = "0.00"
Else
strIn = "#0." & String(MyTextbox.DecimalPlaces, "0")
End If
MyTextbox.Value = Left(CStr(Format(Round(varNewValue,
MyTextbox.DecimalPlaces), strIn)), InStr(CStr(varNewValue), ".") +
MyTextbox.DecimalPlaces - Abs(MyTextbox.DecimalPlaces = 0))
Else
MyTextbox.Value = Format(varNewValue, MyTextbox.Format)
End If
....
MyTextbox.Format MyTextbox.DecimalPlaces Result
Fixed Auto 24.33
Fixed 0 24
Fixed 1 24.3
Fixed 2 24.33
Fixed 3 24.333
Fixed 4 24.3333
Fixed 5 24.33330
Fixed 6 24.333300
Currency Auto $24.33
Short Time Auto 07:59 (almost a third of a day)
Long Time Auto 7:59:57 AM
General Date Auto 1/23/1900 7:59:57 AM
James A. Fortune
CD********@FortuneJames.com