how to increment a recordset ?

hi there....


I have this

RS!f1
RS!f2
RS!f3
RS!f4
RS!f5
etc............

how can I do to use a loop that automaticly increment the recordset ?

like :

for i = 1 to 10
 res = RS!f(i)
next i

(this doesn't work of curse...)

Regards to you all VB helpers ;o)



 



albundyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
VKConnect With a Mentor Commented:
For i = 1 To 10
    res = RS("F" & i)
Next i
:-)
0
 
rkot2000Commented:
option 1

dim x as field (dao or ado)

for each x in rs.fields

debug.print x.value
next

or

dim i as long

for i = 0 to rs.fields.count-1


0
 
Dave_GreeneCommented:
.movenext
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
rkot2000Commented:
option 1

dim x as field (dao or ado)

for each x in rs.fields

debug.print x.value
next

or

dim i as long

for i = 0 to rs.fields.count-1
 debug.print rs.fields(i).value
next i

sorry for previous message  ...
0
 
Dave_GreeneCommented:
Do while not RS.EOF
   res = RS!f(i)
   RS.MoveNext
loop
0
 
DennisBorgCommented:
It is a little unclear to understand precisely what you're looking for.



If your recordset contains several fields , 10 of which are literally named "F1", "F2", "F3", etc., you can use code similiar to the following:

   Dim idxField As Integer

   For idxField = 1 To 10
      Debug.Print rs.Fields("F" & CStr(idxField))
   Next 'idxField




If you are wanting to cycle through *all* the fields in the recordset, regardless of their names, then you can loop through the Fields collection of the recordset with either a numeric index, or by using the For-Each statement (as has been suggested by someone earlier):

   Dim idxField As Integer

   For idxField = 0 To rs.Fields.Count - 1
      Debug.Print rs.Fields(idxField)
   Next 'idxField


   ' *** OR ***


   Dim Fld As Field

   For Each Fld In rs.Fields
      Debug.Print Fld
   Next 'Fld
   Set Fld = Nothing



-Dennis Borg
0
 
wmikeCommented:
dim rst as recordset
rst.movefirst
do while not rst.eof
   rst.movenext
loop
0
 
Dave_GreeneCommented:
wmike, thanks for reposting my suggestion!  I thought it was good also  :)
0
 
rkot2000Commented:
I don?t care about points, but people can post a different solution?
Dave and I posted solutions other solutions just the same.
If you don?t know better or different why ?.?
0
 
DennisBorgCommented:
rkot2000:

>I don?t care about points, but people can post a
>different solution?
>Dave and I posted solutions other solutions just the same.
>If you don?t know better or different why ?.?


I can tell you *why* I posted what I did.

First, I do not post the same answer as someone else. Sometimes, however, I'll read a question and start composing an answer. Meanwhile, someone else also starts composing an answer and then submits their answer before I click on the Submit button. Now, I have no way of knowing that anyone else has also submitted a reply, let alone *what* they said in their reply, until I click on Submit. Only *then* do I see what was submitted while I was typing my own reply. If my answer then happens to be strikingly similiar or identical to someone else's, it is purely coincidential.

Secondly, I may submit a post giving my endorsement of someone else's answer. I sometimes do this when there are various of suggestions and where many of them have problems. I'll then point out the solution I believe the person should use, and I'll explain *why*.


As to why I posted what I did in *THIS* thread, the following comments should explain:

Many of the answers were extremely brief, even to the extent that it may not be helpful to the person asking the question.

   For example, look at Dave Greene's first response:
   (Dave Greene, please note that this is not a personal attack)
----------------------------------
      .movenext
----------------------------------

This reply does not say much; and, depending upon AlBundy's experience level, he may not have a clue as to what ".movenext" is supposed to mean, or how it is to be used.

A bit of dialog, or explanation, even if brief, is often at least as important as the solution itself.

Another thing to note is the fact that I believe that AlBundy was looking for a means of cycling thru the FIELDS, and not cycling thru the RECORDS.



Dave Greene's second reply was quite a bit better, but there is a problem with it:

----------------------------------
      Do while not RS.EOF
        res = RS!f(i)
        RS.MoveNext
      loop
----------------------------------

'f' is not a property or collection of a Recordset Object. This would produce an error. I *think* Dave was trying to compose the name of the field (e.g. "F1", "F2", etc), but I don't know for sure.

Also, one is left to wonder how the variable ' i ' is defined, and from where it obtains its value.


rkot, your comments were fine, although "Option 1" really ought to be "Option Base 1"; but this is a minor problem. Your solution was fine, assuming that AlBundy wanted to cycle through *ALL* fields in the recordset.

But upon reading AlBundy's question, it was not absolutely clear (at least not to me) whether he needed to cycle through *all* fields, or just the ones whose names started with a common prefix (ex: F1, F2, F3, etc); although I suspect it's the latter.

For those reasons, and also due to (what I feel to be) the lack of adequate explaination, I posted my comments. I posted what I considered to be a complete answer, covering both possibilities (all fields, or only certain ones).

I'm sure you noted that I included an acknowlegement that someone else suggested For loops (where I had said "as has been suggested by someone earlier")



I also do not care about the points; but I also feel that the questioner deserves some explaination. I also wanted to make AlBundy aware that he was a little vague as to his objective.

My objective is not to get the points, but to help the person know what the solution is, and also *why* and *how* it works.

This is why I posted my comments.


-Dennis Borg
0
 
Dave_GreeneCommented:
All good points Dennis, no offense taken.
0
 
DennisBorgCommented:
Dave:

>All good points Dennis, no offense taken.

Thank-you, Dave! Incidently, I went to school with a Dave Green.

-Dennis Borg
0
 
wmikeCommented:
Yeah, you're right.
Sorry about that Dave.
0
 
albundyAuthor Commented:
hi

thx to all of you that responded to me :)

anyway the most clear and working code is from VK.

I give you the point pal.

as I can't give point to all of you... I please to not be angry about me ;)

Regards,

Oliver
0
All Courses

From novice to tech pro — start learning today.