Article ID: 181479
Article Last Modified on 3/14/2005
Option Explicit
Dim conn As New Connection
'Dim com As New Command 'Uncomment to make DISTINCT work.
Dim rs As New Recordset
Private Sub Command1_Click()
conn.open "mymachine", "<username>", "<strong password>"
conn.cursorlocation = adUseClient 'Change to aduseServer.
'com.ActiveConnection = conn 'Uncomment to make DISTINCT work.
rs.open "select distinct state from authors", conn, _
adOpenKeyset, adLockOptimistic
MsgBox rs.RecordCount
End Sub
Private Sub Command2_Click()
Dim counter As Integer
counter = 0
conn.Open "dsn=mymachine;Username=<username>;PWD=<strong password>;"
com.ActiveConnection = conn
conn.CursorLocation = adUseClient 'Comment this
'conn.CursorLocation = adUseServer 'and uncomment this.
com.CommandText = "select distinct state from authors"
com.CommandType = adCmdText
rs.CursorType = adOpenKeyset
'cursortype will be adopenforwardonly with adUseServer.
Set rs = com.Execute
While Not rs.EOF
Debug.Print rs!State
counter = counter + 1
rs.MoveNext
Wend
Debug.Print "--------------------"
MsgBox counter 'recordcount return -1 with adUseServer
End Sub
Keywords: kbbug kbfix kbsqlprog kbdatabase kbado210sp2fix KB181479