views:

29

answers:

3

i am getting some data:

rs.Filter = "datapath='" + dpath + "' and analystname='" + aname + "' and reportname='" + rname + "' and batchstate='" + bstate + "'"
If Not rs.EOF Then
    MsgBox rs.Fields("rowid")
End If

if the rs.filter returns multiple records, how do i get rs.fields("rowid") to give me multiple rowid values?

+2  A: 
do while not (rs.eof and not rs.bof)

   MsgBox rs.Fields("rowid") 
   rs.movenext()

end while

Syntax is probably wrong but thats the idea.

Gratzy
hey gratzy thank you very much for the answer can you please incorporate my code into your answer, as im not sure where it should go
I__
+1  A: 

If you simply call rs.Fields("rowId"), you are actually asking for the column value of the current row which is likely to be the first row. Suppose the recordset returns 10 rows, what do you want to do with the rowId value for each of the rows? Show them each in a message box? That means 10 message boxes. If that is really what you wanted to do, you would do something like:

rs.Filter = "datapath='" + dpath + "' and analystname='" + aname + "' and reportname='" + rname + "' and batchstate='" + bstate + "'"
Do Until rs.EOF
    MsgBox rs.Fields("rowid").Value
    rs.MoveNext
Loop

This assumes that rs is a forward-only recordset. If you are using a keyset cursor, then you will likely have to call MoveFirst().

rs.Filter = "datapath='" + dpath + "' and analystname='" + aname + "' and reportname='" + rname + "' and batchstate='" + bstate + "'"
rs.MoveFirst()
Do Until rs.EOF
    MsgBox rs.Fields("rowid").Value
    rs.MoveNext
Loop
Thomas
+1  A: 

This is ADO, so use GetString:

MsgBox rs.GetString

Check first that some records were returned.

More info: http://www.w3schools.com/ado/met_rs_getstring.asp

Remou