percent / 100

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If a user types in a percentage in a form, and I want it to automatically
divide by 100 once it's entered, how do I do that?

example: user wants end result to be 50%, so they type in 50...which will
result in 5000% percent...but I'd like the form to display 50%

thanks...
 
paula k said:
If a user types in a percentage in a form, and I want it to
automatically divide by 100 once it's entered, how do I do that?

example: user wants end result to be 50%, so they type in 50...which
will result in 5000% percent...but I'd like the form to display 50%

If you want to trust that they will never enter, for example, ".5" to
mean 50%, but always "50", you can just divide by 100 in the control's
AfterUpdate event; e.g,

Private Sub txtPercent_AfterUpdate()

With Me!txtPercent
If Not IsNull(.Value) Then
.Value = .Value / 100 ' Adjust for percentage entry
End If
End With

End Sub

If you don't care to trust that, you can check to see if the value
entered is plausible, according to some standard you set. For example,

Private Sub txtPercent_AfterUpdate()

With Me!txtPercent
If Not IsNull(.Value) Then
If .Value > 1 Then
.Value = .Value / 100 ' Adjust for percentage entry
End If
End If
End With

End Sub
 

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