tech on the net
Home About Us Feedback Site Map

Microsoft

Access Excel Word

Database

SQL Oracle / PLSQL SQL Server MySQL MariaDB PostgreSQL

Web Development

HTML CSS Color Picker

Language

C Language

More

ASCII Table Linux UNIX Java Clipart Joke of the Moment
Share this page:

MS Access: Rnd Function

Learn how to use the Access Rnd function with syntax and examples.

Description

The Microsoft Access Rnd function allows you to generate a random number (integer value). You can specify the random number to be a value between 2 user-specified numbers.

Syntax

The syntax for the Microsoft Access Rnd function is:

Int ((upperbound - lowerbound + 1) * Rnd + lowerbound)

Parameters or Arguments

upperbound is the highest value that the random number can be.

lowerbound is the lowest value that the random number can be.

Applies To

The Rnd function can be used in the following versions of Microsoft Access:

Example

Int ((6 - 1 + 1) * Rnd + 1) would return a random number between 1 and 6
Int ((200 - 150 + 1) * Rnd + 150) would return a random number between 150 and 200
Int ((999 - 100 + 1) * Rnd + 100) would return a random number between 100 and 999

Example (in VBA Code)

The Rnd function can be used in VBA code in Microsoft Access. For example:

Dim LRandomNumber As Integer

LRandomNumber = Int ((300 - 200 + 1) * Rnd + 200)

In this example, the variable called LRandomNumber would now contain a random number between 200 and 300.

Example (in SQL/Queries)

You can also use the Rnd function in a query in Microsoft Access.

Microsoft Access