Link to home
Start Free TrialLog in
Avatar of Cerixus
CerixusFlag for United States of America

asked on

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
		RS.Movenext()
	wend

Open in new window

Avatar of stefanx
stefanx

Looks fine to me, so it must be something with the RS.MoveNext() ?
Maybe just make it RS.MoveNext without the parentheses ?
Avatar of Cerixus

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Cerixus
Cerixus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial