ADODB

M

Mr Struggler

The following code cycles through the recordset OK, but the RS.RecordCount
is allways = -1. I Need to be able to run a query from which I can tell if a
record exists, if I cant determine the record count I dont know how to
procede

Any help is appreciated


Sub Northwind()

Dim rs As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rec As New ADODB.Record

Dim sqlString As String
sqlString = "SELECT * FROM CUSTOMERS"

con.ConnectionString = "Driver={SQL
Server};Server=MYSERVER;Database=NORTHWIND;Uid=sa;Pwd=password;"
con.Open
cmd.ActiveConnection = con
cmd.CommandText = sqlString
cmd.CommandType = adCmdText

Set rs = cmd.Execute(sqlString)

rs.MoveFirst
Do While Not rs.EOF
Debug.Print rs.Fields(0)
rs.MoveNext
Loop

con.Close
Set con = Nothing
Set cmd = Nothing
End Sub
 
R

Robin Hammond

Try this syntax which sets your cursor type:

rs.Open sqlString, con, adOpenStatic, adLockBatchOptimistic, adCmdText
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top