Solved

how to increment a recordset ?

Posted on 2001-07-18
14
301 Views
Last Modified: 2011-10-03
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)



 



0
Comment
Question by:albundy
  • 4
  • 3
  • 3
  • +3
14 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6295125
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
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6295127
.movenext
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6295130
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
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6295135
Do while not RS.EOF
   res = RS!f(i)
   RS.MoveNext
loop
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6295275
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
 

Expert Comment

by:wmike
ID: 6295339
dim rst as recordset
rst.movefirst
do while not rst.eof
   rst.movenext
loop
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6295367
wmike, thanks for reposting my suggestion!  I thought it was good also  :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Accepted Solution

by:
VK earned 50 total points
ID: 6295558
For i = 1 To 10
    res = RS("F" & i)
Next i
:-)
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6295568
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
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6295797
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
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6295820
All good points Dennis, no offense taken.
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6295849
Dave:

>All good points Dennis, no offense taken.

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

-Dennis Borg
0
 

Expert Comment

by:wmike
ID: 6296830
Yeah, you're right.
Sorry about that Dave.
0
 

Author Comment

by:albundy
ID: 6297205
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 51
VB error "Type mismatch" 2 49
VB 6 error 5 in windows 10 but not in XP 7 40
Advice in Xamarin 21 47
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

932 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

17 Experts available now in Live!

Get 1:1 Help Now