Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do... Loop Nesting and Runtime Error '6' - Overflow

Status
Not open for further replies.

FRIDL125

MIS
Mar 29, 2002
9
US
I have the following code and when I attempt to run it, it doesn't loop properly.

The underlying table from which I am pulling data contains 1000 records. The field length is 20.

The online help hasn't helped me at all and I'm wondering if anyone is seeing anything that stands out as being incorrect?

TIA,
Lisa

************Code*******************
Set rstAccountNumber = dbsCurrent.OpenRecordset("tblAccounts", dbOpenDynaset)
Set rstStrings = dbsCurrent.OpenRecordset("tblStrings", dbOpenDynaset)

rstAccountNumber.MoveLast
LastAcct = rstAccountNumber![AccountNumber]
rstAccountNumber.MoveFirst
FirstAcct = BeginAcct

Do
For i = BeginAcct To LastAcct
CurAcct = rstAccountNumber![AccountNumber]
FDRSess.Screen.SendKeys &quot;BS &quot; & CurAcct & &quot;<Enter>&quot;
Phone = FDRSess.Screen.GetString(4, 67, 4, 78)
FDRSess.Screen.SendKeys &quot;<Home>CIS<Enter>&quot;
NameString = FDRSess.Screen.GetString(2, 1, 2, 80)

Do
For j = 2 To 24
InitialCheck = FDRSess.Screen.GetString(j, 23, 80)
If InitialCheck = &quot;BC *&quot; Then
MemoString = InitialCheck

rstStrings.AddNew
rstStrings![AccountNumber] = CurAcct
rstStrings![NameString] = NameString
rstStrings![MemoLine] = MemoString
rstStrings![Phone] = Phone
rstStrings.Update

End If
Next j
Loop Until j = 2


If CurAcct = LastAcct Then
MsgBox &quot;Complete&quot;
End If
Exit Do

Next i

Loop Until i = LastAcct


End Function
 
Lisa,

Even though you are no longer getting the Runtime error, I want to point out a couple of things:

1) The Do loops appear to be superfluous; i.e. the real looping work is carried out in both cases by the For..Next loops.
2) Referencing a For..Next loop counter (i & j in your code) outside the loop construct is not a good idea. I conducted a test: I set up a For..Next loop inside a Do..Until loop, each using the same control variable and termination value, as in your code. When the For..Next counter reached the terminating value, the loop exited, as expected, but the loop counter variable increased by one. Because of this, the Do..Loop termination value was skipped, resulting in an infinite loop.

Hope this helps.
M. Smith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top