Question concerning a For statement in a Db

bknight
BronzeLounger
Posts: 1412
Joined: 08 Jul 2016, 18:53

Question concerning a For statement in a Db

Post by bknight »

I have a Db of ~10K records.
There is a for statement I= 1 to Rs.RecordCount. Now I want to assume that record 9224 is correct and only succeeding records need to be edited/calculated. If I change the for statement to I = 9224 to Rs.RecordCount will the code start manipulations at record 9224? Perhaps a dumb question but I want to be sure prior to proceding.
Last edited by HansV on 29 Sep 2023, 12:03, edited 1 time in total.
Reason: to correct typo in subject

robertocm
Lounger
Posts: 43
Joined: 07 Jun 2023, 15:34

Re: Question concerning a for staetment in a Db

Post by robertocm »

If the WHERE returns all records and inside the For loop there is a Rs.MoveNext,
i think the counter should start at 1 to be synchronize (active record = counter number).

snb
4StarLounger
Posts: 588
Joined: 14 Nov 2012, 16:06

Re: Question concerning a for staetment in a Db

Post by snb »

Code: Select all

.Move 9224, 1

User avatar
Gasman
2StarLounger
Posts: 117
Joined: 22 Feb 2022, 09:04

Re: Question concerning a for staetment in a Db

Post by Gasman »

Why not just walk through the code?
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

bknight
BronzeLounger
Posts: 1412
Joined: 08 Jul 2016, 18:53

Re: Question concerning a for staetment in a Db

Post by bknight »

snb wrote:
29 Sep 2023, 09:49

Code: Select all

.Move 9224, 1
Never used that one, but if it works, it would be fine, I think.
Stepping through the code would work. I could try that also.

bknight
BronzeLounger
Posts: 1412
Joined: 08 Jul 2016, 18:53

Re: Question concerning a For statement in a Db

Post by bknight »

This is an old code probably 30 yrs. that I'm rewriting. First error

Code: Select all

Set db = CurrentDb
Set Rs = db.OpenRecordset("Select * From tblMcClellan Order By Index")
Gives me a run time error: to few parameters, expected one.
ETA: Never mind found it quickly, I renamed the Index DateIndex.

bknight
BronzeLounger
Posts: 1412
Joined: 08 Jul 2016, 18:53

Re: Question concerning a For statement in a Db

Post by bknight »

Now this is strange

Code: Select all

Rs.MoveFirst
Rs,MoveLast
Rs.MoveFirst
Rs.Move 9223
I commented out the second Rs.MoveFirst and all the watch values were blank, so I reinserted that line, but when executed the record number values are from record 9224? I can work with it, but why is the next record selected?

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Question concerning a For statement in a Db

Post by HansV »

The argument of Move is the number of records to move, not the absolute position of the record to move to.

After Rs.MioveFirst, you're at record number 1.
Rs.Move 9223 moves 9223 records forward from the current record, so you end up at record number 1+9223 = 9224

If you comment out the second Rs.MoveFirst, you're at the last record. Executing Rs.Move 9223 positions you after the end of the recordset.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1412
Joined: 08 Jul 2016, 18:53

Re: Question concerning a For statement in a Db

Post by bknight »

Ok, I assumed it was a move to that number but your information makes sense.
Thanks

bknight
BronzeLounger
Posts: 1412
Joined: 08 Jul 2016, 18:53

Re: Question concerning a For statement in a Db

Post by bknight »

As promised here is the data and calculated values for 3 Jan 23. The formulas are in the code a few lines back. 3 Jan is fixed and should not be manipulated.
You do not have the required permissions to view the files attached to this post.