Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    working with percent fields (2000)

    I have a percent field and I want to able to enter 5 and for this to be changed to 5%. I'm hoping that this can be done just using the Format or InputMask property? Any suggestions? Andy.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: working with percent fields (2000)

    If you mean you have a field with the display format set to percentage, then no, you can't just enter 5 and have it formatted as 5%. The display format takes the value and shows it as a percent. To get 5%, you would have to enter .05, with is the value represented by 5%. It you want to just enter 5, you would need to put code in the AfterUpdate event of the control to divide the value by 100. It would look something like this:

    <pre>Private Sub PValue_AfterUpdate()
    If Me.PValue >= 1 Then
    Me.PValue = Me.PValue / 100
    End If
    End Sub</pre>


    Testing for a value >=1 means that if you actually do enter a value like .05, it will still be formatted as 5%.
    Charlotte

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: working with percent fields (2000)

    An input mask doesn't help here, I think.

    If you set the format to percentage, entering 5 will result in 500% (not what you wanted), and entering 5% will result in 5% (as intended).

    If you don't want to enter the % sign, you could do the following:
    <UL><LI>Don't set the format to percentage.
    <LI>Store the number as entered (if you enter 5, you store 5 in the field.)
    <LI>On the data entry form, put a label with % as caption after the text box bound to the field.
    <LI>Divide by 100 in all calculations involving the field.[/list]

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: working with percent fields (2000)

    Thank you. I tried amending the Format property to 0%, but you either have to enter the percent sign again, or amend the selection to just overtype the number part. Andy.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: working with percent fields (2000)

    I assume you're looking at Hans suggestion and responding to him, since my code doesn't require removing the percent format.
    Charlotte

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: working with percent fields (2000)

    If this is what you mean:-

    I've set the format for the field to "Percentage" and then divided by 100 after update.
    Attached Files Attached Files

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: working with percent fields (2000)

    Close. In my code I tested for a value > = 1 rather then testing for a Null value. The way you did it will always divide any number it finds by 100. The way I did it will divide any positive number of 1 or greater by 100 under the assumption that some people will still want to enter .05 for 5%. Either way will work depending on what the user needs to do. If some of the entries might be negative, then my code will not divide those by 100 while yours will.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •