vbscript step through SQL results

The attached code properly displays the message box for the first record that matches the criteria, however it then just repeats the messagebox for the same record indefinitely.  I've used a similar setup before, but it was ASP.  This is straight VBS and I must be missing something simple.
	counter = 0
	limit = 5
	Dim cConnection
	Set cConnection = CreateObject("ADODB.Connection")
	//setting variables here for connection string, username, password.
	cConnection.Open DBConString,DBUser,DBPass
	SQLstmt = "SELECT field1, field2 from Table1 WHERE Field1 IS NULL"
	Set RS = cConnection.Execute(SQLstmt)
	while (not RS.EOF) AND (counter < limit)
		msgbox("Field1: " & RS.Fields.Item("field1").value)
		//do other stuff
		counter = counter + 1

Open in new window

Who is Participating?
CerixusConnect With a Mentor Author Commented:

In that whole //do other stuff section I had a function that was doing a database insert.  Stupidly, I was using RS for the recordset name.  Changed it to RS2 and now everything is working.
Looks fine to me, so it must be something with the RS.MoveNext() ?
Maybe just make it RS.MoveNext without the parentheses ?
CerixusAuthor Commented:
No, it's apparently because I'm using ADODB.Connection and need to define and use a recordset... though I'm not entirely sure how to get to that point using a DSNless connection.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.