Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Brugge, Belgium
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Declaring variables (Ms Access 2007)

    In a Access table we can precise the type of the field, and so we can define a field of type currency and precise percent.
    But how can we precise in vba code that the value in a variable must be interpreted as a percent value?

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

    Re: Declaring variables (Ms Access 2007)

    Percent is not a specific data type, it's just a way to display data. Since using percentages involves working with decimals (1% = 1/100 or 0.01 of something), you can declare a variable as Single or Double if you want to use it in calculations involving percents.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Brugge, Belgium
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Declaring variables (Ms Access 2007)

    The reason why i asked this question is because in MS access 2007 the working with percent values is different from what it was in MS Access 2.0
    There indeed , when using such avalues in a calculation we had to use a small sub to divide the value by 100 before making any calculation with this value.
    In MS Access 2007 this isn't anymore necessary. So I just asked this question to know if this new way aof calculating is also is applicable on values that are declared is single or double.
    I thought that there was a way in code to precise that the value has to be interpreted as percent, and this way the same rules can be applied to this value as is the case for a percent value in a field of a table.

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

    Re: Declaring variables (Ms Access 2007)

    There is no such thing as a percentage field, data type or variable type.
    But you can specify that a field or text box is formatted as a percentage. If the user enters 37%, Access automatically divides the number by 100, i.e. the value actually stored in the field is 37/100 = 0.37, and this value 0.37 is used in all calculations involving the field or text box.
    There is no direct equivalent for VBA variables, i.e. there is no setting that tells VBA to automatically divide the value of a variable by 100 in calculations. You will have to do that yourself.

Posting Permissions

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