Solved

Help with loop

Posted on 1998-08-19
4
129 Views
Last Modified: 2010-04-30
VB5  f= MSFlexgrid, rs = DAO recordset
Following loop is not looping it returns only last record in
the recordset and places it in the grid.
///
Do Until rs.EOF
str = ""
For i = 0 To rs.Fields.Count - 1
str = str & rs.Fields(i).Value & vbTab
Next i
f.AddItem str
rs.MoveNext
Loop
///
anu help appreciated
0
Comment
Question by:mativare
  • 2
4 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1429954
Code looks OK...


1. Set a break point on str = ""
2. Insert a Debug.Print before Next i
3. Run (F5)
4. Step through the code using the F8 Key
5. After executing the Debug.Print, check the intermediate window CTRL G

You should see the value of str in that window.
You are checking to make sure your record set is there...

0
 
LVL 4

Expert Comment

by:mcix
ID: 1429955
Code looks OK...


1. Set a break point on str = ""
2. Insert a Debug.Print before Next i
3. Run (F5)
4. Step through the code using the F8 Key
5. After executing the Debug.Print, check the intermediate window CTRL G

You should see the value of str in that window.
You are checking to make sure your record set is there...

0
 
LVL 2

Expert Comment

by:richtsteig
ID: 1429956
I hope you just forgot to post the rs.movefirst?!
0
 
LVL 1

Accepted Solution

by:
blwatkins earned 50 total points
ID: 1429957
Place a RS.MoveLast and a RS.MoveFirst before your "Do Until" statement.
this will but you at the begining of your recordset.

Then do a little test to see how many records are in your recordset, to make sure you have more than one record.
Right after the above command put this:
  Msgbox ("Number of Records: " & rs.recordcount)

This will show you the number of records in your recordset.

I have the feeling you only have one record in your recordset.

The rest of your code looks fine.


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question