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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerate recordset 1

Status
Not open for further replies.

richardii

Programmer
Jan 8, 2001
104
GB
I have a table called Tbl, and try to run this code on it. It will only list the data in the first row - what am I doing wrong!

Function e_num()
Dim dbs As Database
Dim fld As Field
Dim rst As Recordset
Dim i As Integer
i = 0
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Tbl", dbOpenSnapshot)

With rst
rst.MoveLast
rst.MoveFirst

Do While Not rst.EOF
Do While i < rst.Fields.Count
Set fld = rst.Fields(i)
MsgBox fld.Name &amp; &quot; = &quot; &amp; fld.Value
i = i + 1
Loop
rst.MoveNext
Loop

End With
End Function
 
I forget to reset the counter i, after the first Do, don't I......
 
A minor note.

You don't need the &quot;rst&quot; between the &quot;With&quot; &amp; &quot;End With&quot; statements.

The move last &amp; move First Statements are counter productive. They just use up time traversing the recordset.

The Do While / Loop construct could be accomplished more easily with a For/next loop to save you having to rember to increment the counter, as in

For I = 1 to .Fields.Count - 1[tab][tab]'not the LACK of the &quot;rst&quot;
[tab][tab].
[tab][tab].
[tab][tab].
[tab][tab].
Next I

MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top