Solved

Help with loop

Posted on 1998-08-19
4
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

696 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