Loop, then add 1 to the value...

VegaLA

Registered User.
Local time
Today, 00:41
Joined
Jul 12, 2006
Messages
101
Hi all,
trying to run this code that should insert '1' into the first record then adds a value to that and then inserts that to the next record (value 2) and inserts that into the next field until it comes to the end of the recordset of the query but I am getting this error message:- Too few parameters, expected 1.

Dim db As Database
Dim rs As Recordset
Dim intPosition As Integer

Set db = CurrentDb

Set rs = db.OpenRecordset("qryMyQuery")

intPosition = 0
rs.MoveFirst
Do While Not rs.EOF
rs.Edit
rs!Rating = intPosition + 1
rs.Update
rs.MoveNext
Loop

rs.Close

I thought it should be pretty straight forwards but I have messed up somewhere. Can anyone see wheer I went wrong ?

Thanks in advance,
Mitch.....
 
Would really need to see the SQL of your query and the line where the error occurs there's also a problem with your intposition in the loop, I can guess where it's happening, but I've jumped to a few too many conclusions this week:

Code:
intPosition = 1
rs.MoveFirst
Do While Not rs.EOF
  rs.Edit
  rs!Rating = intPosition 
  rs.Update
  rs.MoveNext
  intposition = intposition + 1
Loop
 
Thanks Nellie.
Your suspicions are correct, stepping through the code it errors up when it calls the qry but opening the qry itself and manually adding the values works fine.
The code is as follows:-

SELECT tblTopServicersLOCAL.Rating, tblTopServicersLOCAL.Servicer, tblTopServicersLOCAL.LoanCount, tblTopServicersLOCAL.EndUPB, tblTopServicersLOCAL.CDate
FROM tblTopServicersLOCAL
WHERE (((tblTopServicersLOCAL.CDate)=[forms]![frmInput].[txtcutday] Or (tblTopServicersLOCAL.CDate)=#10/31/2007#));

Any ideas?

Thanks again,
Mitch...
 

Users who are viewing this thread

Back
Top Bottom