View Single Post
  #1 (permalink)  
Old September 30th, 2004, 08:21 AM
goels goels is offline
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nested Do Until Loop

Hi Everyone,

When I test the below given code in the immediate window of VBA Editor the innermost loop functions while the outer loop is not entered into after the innermost loop has finished.

Option Compare Database
Option Explicit

Sub EasyScript()

Dim db As Database
Dim rec As Recordset
Dim rec1 As Recordset
Dim accountname As String
Dim Date1 As String


Set db = CurrentDb()
Set rec = db.OpenRecordset("tbl_accountname")
Set rec1 = db.OpenRecordset("tbl_date")

Do Until rec.EOF
accountname = rec(2)
Do Until rec1.EOF
Date1 = rec1(2)
Debug.Print accountname
Debug.Print Date1
rec1.MoveNext
Loop
rec.MoveNext
Loop


End Sub

The data that comes in rec(2) one-by-one is : 00, 01, 02 & 03
The data comes in rec1(2) one-by-one is : 00 & 01

A run of the code gives:

00
00
00
01

Whearas it should be giving:

00
00
00
01
01
00
01
01
02
00
02
02
03
00
03
01

I cannot make out why this is happening. I am new to VBA and i could be possibly making some very foolish mistake. Please bear with me.

Chow
Goels