To display a number with a trailing percent sign, use one of the following two methods.
Method1
This method uses a custom function to return the formatted number:
- Create a new module, and then type the following line in the Declarations section:
Option Explicit
- Type or paste the following code in the module:
Function FormatNumber(Num)
FormatNumber = Format(Num, "0.00") & " %"
End Function
- Set the ControlSource property of a text field that you want to format with the percent sign to the following expression:
= FormatNumber([Field1])
Method 2
This method involves creating a query with a calculated field that corrects the error introduced when a percent sign is used in the
Format statement. To use this method, follow these steps:
- Start Microsoft Access and open any database
- Create a table with the following structure:
Table: Table1
------------------
Field Name: Score
Data Type: Number
Field Name: MaxScore
Data Type: Number
- View the Table1 table in Datasheet view and type the following records:
Score��� MaxScore
-----------------
20������� 40
60������� 180
- Create the following query based on the Table1 table:
Query: Query1
-----------------
Field: %Score: Format([Score]/[MaxScore],"0.00%")
- Run the query. Note that Field1 displays the correct value followed by the percent sign.
NOTE: The output of the
Format statement is always a text string. The two methods listed here are useful for forms or reports where you display only the percentage value. This technique does not work in situations where you need to treat the value as a number. If you need the value to be represented by a number, do not use the
Format statement. Instead, you can add a label control containing the percent sign immediately to the right of the text box control.