Tag Archives: Loops

Looping Through a Recordset

In this blog post we will be demonstrating how to loop through a recordset. Recordsets act like a cursor or a ruler underneath a row of data.  They only operate on one row at a time so to access the data returned by the database we must Move the cursor Next or Previous, First or […]

What are Recordsets

In this blog post we will be introducing recordsets and providing some examples of their use. So, what is a recordset? You can think of a recordset as a table or query that we can utilise (read, update, delete, insert) but cannot see. When we open a recordset, the recordset itself is stored in memory […]

DoEvents

In this blog post we discuss the DoEvents method in VBA. DoEvents is a simple command that pauses a loop and allows the operating system to carry out any tasks that have been queued. If you have a loop that can take a significant time to fire, DoEvents enables the loop to pause at periodic […]

Nested Loops

In this blog post we will be discussing nested loops and how they can be used. A loop inside a loop is termed a nested loop. We’ll make a grid of numbers to illustrate. Sub nestedLoop1() Dim y As Integer Dim x As Integer Dim xString As String For y = 0 To 9 ‘We […]

Loops – Do Until / Do While / Do

In this blog post we will be discussing the Do..Until/While loop. The Do…While loop keeps executing the loop as long as a certain condition is met. Sub doWhile1()          Dim i As Long     Dim kitchenItems(0 To 5) As String     ‘We have created an array that can hold 6 elements     […]

Loops – While Wend

In this blog post we take a look at the While…Wend Loop. The basic syntax of a While loop is: While(someExpression) … Wend The loop will continue to operate as long as someExpression is equal to true. When it becomes false, the while loop exits. Sub whileLoopArray()     Dim i As Long     Dim kitchenItems(0 […]

Loops – For Each

In this blog post we will be explaining the For…Each loop and providing some examples of its usage. Demonstrating The For Each Loop with An Array We can use the For Each loop over a standard array. Sub forEachArray()          Dim element As Variant     Dim animals(0 To 5) As String     ‘We […]

Loops – For Next

In this blog post we will introduce the For…Next Loop and provide some examples of its usage. The standard syntax of a For…Next loop is: For counter = start To end … next i In the code above counter is a variable that keeps track of the number of loops performed. start is the starting […]