Solved

vbscript step through SQL results

Posted on 2009-07-09
3
195 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:Cerixus
  • 2
3 Comments
 
LVL 8

Expert Comment

by:stefanx
ID: 24817840
Looks fine to me, so it must be something with the RS.MoveNext() ?
Maybe just make it RS.MoveNext without the parentheses ?
0
 
LVL 1

Author Comment

by:Cerixus
ID: 24817867
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.
0
 
LVL 1

Accepted Solution

by:
Cerixus earned 0 total points
ID: 24818063
:facepalm:

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.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 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

10 Experts available now in Live!

Get 1:1 Help Now