MS Access: Mod Function
This MSAccess tutorial explains how to use the Access Mod function with syntax and examples.
Description
The Microsoft Access Mod function returns the remainder after a number is divided by a divisor.
Syntax
The syntax for the Mod function in MS Access is:
number Mod divisor
Parameters or Arguments
- number
- A numeric value whose remainder you wish to find.
- divisor
- The number used to divide into the number parameter.
Returns
The Mod function returns a numeric value.
Applies To
The Mod function can be used in the following versions of Microsoft Access:
- Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000
Example
Let's look at how to use the Mod function in MS Access:
19 Mod 17
Result: 2
19 Mod -13
Result: 6
34 Mod 17
Result: 0
34 Mod 0
Result: Run-time error '11': Division by zero
Example in VBA Code
The Mod function can be used in VBA code in Microsoft Access.
For example:
Dim LNumber As Integer LNumber = 19 Mod 17
In this example, the variable called LNumber would now contain the value of 2.
Example in SQL/Queries
You can also use the Mod function in a query in Microsoft Access.
For example:
In this query, we have used the Mod function as follows:
Expr1: [Quantity] Mod 10
This query will return the remainder of the Quantity field divided by 10 and display the results in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.
For example:
RemainderValue: [Quantity] Mod 10
The results would now be displayed in a column called RemainderValue.
Advertisements