PDA

View Full Version : Display percent value



av8tordude
04-08-2010, 03:59 PM
The code below displays values in decimal format. (Ex: 0.25) How do I get it to display as a percent value. (Ex: 25%)


Select Case Len(Me.MPct)
Case 1
Me.PPct = Format(Me.PPct, "0\.00")
Case Is > 1
v = Replace(Me.PPct, ".", "")
Me.PPct = Format(Val(v), "0\.00")
End Select

Trebor76
04-08-2010, 04:50 PM
Hi ,

Can't test the following without having the form it relates to but see how this goes:


Select Case Len(Me.MPct)
Case 1
Me.PPct = Format(Me.PPct, "0\.00%")
Case Is > 1
v = Replace(Me.PPct, ".", "")
Me.PPct = Format(Val(v), "0\.00%")
End Select

HTH

Robert

av8tordude
04-08-2010, 05:32 PM
didn't work. I attached an example. whenever I type a number in the textbox, it errors: Overflow

Trebor76
04-08-2010, 07:06 PM
It's because it's getting stuck in what seems to be endless loop i.e. each time the format of the field is changed the code fires off again.
See if the attached suffices.

mdmackillop
04-09-2010, 06:00 AM
More simply

Private Sub PPct_AfterUpdate()
Me.PPct = Format(Me.PPct, "0.00%")
End Sub

av8tordude
04-16-2010, 05:51 AM
I wanted to provide a solution to my original request for future references in case any one else needed a similar solution. This code was provided by my good friend Ger Plante.


Private Sub PPct_Change()
Dim v As String

v = Replace(Me.PPct, "%", "")
Me.PPct = Val(v) & "%"
End Sub