MS Access Do-While Statement

MS Access Do-While Statement

MS Access Do-While Statement repeats a block of statements while a Boolean condition is True or until the condition becomes True. In short, use a Do-While statement when you want to repeat a set of statements for an indefinite number of times, until a condition is satisfied.

In our downloadable example, we specified the first field to be the number of repeats. For instance, if your input is “5”, then the command “Run Do-While” will repeat the calculations for 5 times i.e., when the condition became True. The command button “Run Do-While”, however, will do a random calculation based on your mathematical symbol, i.e., “+, -, *, or /” for a number of times which you had already specified.

Basic Syntax of Do-While Statement:

				
					Do { While | Until } condition
   [ statements ]
   [ Continue Do ]
   [ statements ]
   [ Exit Do ]
   [ statements ]
Loop
				
			

Additional Statements used in our example:

In our downloadable example, we used more functions than Do-While Statements. These functions are listed below and you can follow the links if you would like to learn more about these statements:

  1. Insert into / Delete Statement using MS Access VBA codes (Microsoft Access SQL)
  2. Select Case Statement
  3. Random Function

Random Function:

The Microsoft Access Random Function (Rnd function) allows you to generate a random number (integer value). 

Syntax of Rnd Function:

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

Parameters of Rnd Function:

  • Upperbound: The highest value that the random number can be.
  • Lowerbound: The lowest value that the random number can be.

Download an Example:

				
					Dim intRandom As Integer
intRandom = Int ((999 - 100 + 1) * Rnd + 100)
				
			

In this example, the variable called intRandom would contain a random number between 100 and 999.

For more pro MS Access Programs, please visit our home page here.
For more information about “MS Access Do-While Statement”, Please Visit Microsoft Access Support page here.