Percentage question

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

Guest

one more question - the predesigned format for percentage multiplies it by
100. How would you override that? meaning right now I enter 4 and it she
400.00% and I want it to look like 4.00% Is there a way to do this - thanks
for all your help I am a newbie

Zenia
 
Save this function into a standard module (Modules tab of Database window.)

Public Function MakePercent(txt As TextBox)
If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
End Function

Now you can set the AfterUpdate property of any text box to call this
function. For example, you would set the AfterUpdate property of Text23 to:
=MakePercent([Text23])

The function works by examining the Text property of the control. That's the
actual text the user typed into the control, as distinct from its Value. If
the user did not type a percent sign, the function divides the value by 100.
 
This question gets asked from time to time, so there is now a page with a
more complete version of this function (includes error handling) in this
article:
Enter a value as a percent
at
http://allenbrowne.com/casu-16.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Allen Browne said:
Save this function into a standard module (Modules tab of Database
window.)

Public Function MakePercent(txt As TextBox)
If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
End Function

Now you can set the AfterUpdate property of any text box to call this
function. For example, you would set the AfterUpdate property of Text23
to:
=MakePercent([Text23])

The function works by examining the Text property of the control. That's
the actual text the user typed into the control, as distinct from its
Value. If the user did not type a percent sign, the function divides the
value by 100.


esparzaone said:
one more question - the predesigned format for percentage multiplies it
by
100. How would you override that? meaning right now I enter 4 and it
she
400.00% and I want it to look like 4.00% Is there a way to do this -
thanks
for all your help I am a newbie

Zenia
 
evidently i'm missing something. i the code mentioned here.

i have a txt field [%Complete]

i call the field in my form:

After Update =MakePercent([%Complete])

when i enter 25, it converts to 0.25

i want to enter 25, and it convert to 25%

how do i do this?

Allen Browne said:
Save this function into a standard module (Modules tab of Database window.)

Public Function MakePercent(txt As TextBox)
If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
End Function

Now you can set the AfterUpdate property of any text box to call this
function. For example, you would set the AfterUpdate property of Text23 to:
=MakePercent([Text23])

The function works by examining the Text property of the control. That's the
actual text the user typed into the control, as distinct from its Value. If
the user did not type a percent sign, the function divides the value by 100.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

esparzaone said:
one more question - the predesigned format for percentage multiplies it
by
100. How would you override that? meaning right now I enter 4 and it she
400.00% and I want it to look like 4.00% Is there a way to do this -
thanks
for all your help I am a newbie

Zenia
 
Did you ever get this to work. If not, I can tell you what I did to get it
to work.

Joel

samuel said:
evidently i'm missing something. i the code mentioned here.

i have a txt field [%Complete]

i call the field in my form:

After Update =MakePercent([%Complete])

when i enter 25, it converts to 0.25

i want to enter 25, and it convert to 25%

how do i do this?

Allen Browne said:
Save this function into a standard module (Modules tab of Database window.)

Public Function MakePercent(txt As TextBox)
If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
End Function

Now you can set the AfterUpdate property of any text box to call this
function. For example, you would set the AfterUpdate property of Text23 to:
=MakePercent([Text23])

The function works by examining the Text property of the control. That's the
actual text the user typed into the control, as distinct from its Value. If
the user did not type a percent sign, the function divides the value by 100.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

esparzaone said:
one more question - the predesigned format for percentage multiplies it
by
100. How would you override that? meaning right now I enter 4 and it she
400.00% and I want it to look like 4.00% Is there a way to do this -
thanks
for all your help I am a newbie

Zenia
 
please do.

Jase4now said:
Did you ever get this to work. If not, I can tell you what I did to get it
to work.

Joel

samuel said:
evidently i'm missing something. i the code mentioned here.

i have a txt field [%Complete]

i call the field in my form:

After Update =MakePercent([%Complete])

when i enter 25, it converts to 0.25

i want to enter 25, and it convert to 25%

how do i do this?

Allen Browne said:
Save this function into a standard module (Modules tab of Database window.)

Public Function MakePercent(txt As TextBox)
If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
End Function

Now you can set the AfterUpdate property of any text box to call this
function. For example, you would set the AfterUpdate property of Text23 to:
=MakePercent([Text23])

The function works by examining the Text property of the control. That's the
actual text the user typed into the control, as distinct from its Value. If
the user did not type a percent sign, the function divides the value by 100.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

one more question - the predesigned format for percentage multiplies it
by
100. How would you override that? meaning right now I enter 4 and it she
400.00% and I want it to look like 4.00% Is there a way to do this -
thanks
for all your help I am a newbie

Zenia
 
First I inserted a module, then I copied and pasted this from Allen Browne's
response

Public Function MakePercent(txt As TextBox)
If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
End Function

I didn't change a thing to the code above. Then, I saved and closed the
'code' view, went back to my form in 'design' view, clicked on the text box
in question and viewed PROPERTIES. On the event tab where it says 'After
Update' I pasted =MakePercent([Text23]). I changed "Text23" to the name of
my text box, and I haven't had any problems. Now when i type "25" on my form
it returns 25.00%.

I hope this helps,

Joel



samuel said:
please do.

Jase4now said:
Did you ever get this to work. If not, I can tell you what I did to get it
to work.

Joel

samuel said:
evidently i'm missing something. i the code mentioned here.

i have a txt field [%Complete]

i call the field in my form:

After Update =MakePercent([%Complete])

when i enter 25, it converts to 0.25

i want to enter 25, and it convert to 25%

how do i do this?

:

Save this function into a standard module (Modules tab of Database window.)

Public Function MakePercent(txt As TextBox)
If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
End Function

Now you can set the AfterUpdate property of any text box to call this
function. For example, you would set the AfterUpdate property of Text23 to:
=MakePercent([Text23])

The function works by examining the Text property of the control. That's the
actual text the user typed into the control, as distinct from its Value. If
the user did not type a percent sign, the function divides the value by 100.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

one more question - the predesigned format for percentage multiplies it
by
100. How would you override that? meaning right now I enter 4 and it she
400.00% and I want it to look like 4.00% Is there a way to do this -
thanks
for all your help I am a newbie

Zenia
 
Back
Top