Solved

Help with loop

Posted on 1998-08-19
4
126 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now