I have a recordset that I use to load a grid on a form. I added a filter option to the grid. The filter works, but when I set the filter command, it is running the same query as the first time then applying the filter. I'm using the SQL profiler to optimize the program. I've been trying the different CursorTypes and cursor locations with no change in the behavior.
The recordset does not need to be updateable. I'm using SQL Server 2000. Can anyone see what I'm doing wrong?
I created a small program that simulates what I'm doing so that I can try the different options easier than doing it in the actual application. Here's the button event code from my test app. This is all of the code.
Thanks,
Paul
Private Sub Command2_Click()
Dim objCommand As ADODB.Command
Dim objRecordSet As ADODB.Recordset
Dim sSQL As String
Dim objSQLConnection As ADODB.Connection
Set objSQLConnection = New ADODB.Connection
Call objSQLConnection.Open("LocalServer"
Set objCommand = New ADODB.Command
objCommand.ActiveConnection = objSQLConnection
sSQL = sSQL & " Use Pubs SELECT Stor_ID FROM Sales WHERE Stor_ID like '7%'"
objCommand.CommandText = sSQL
Set objRecordSet = New ADODB.Recordset
objRecordSet.CursorLocation = adUseClient
objRecordSet.CursorType = adOpenKeyset
Set objRecordSet = objCommand.Execute
'Simulate loading a grid...
While Not objRecordSet.EOF
Debug.Print objRecordSet!Stor_ID
objRecordSet.MoveNext
Wend
'Set a filter - This is where it's executing the query again
objRecordSet.Filter = "Stor_ID like '70%'"
'Reload the grid
If Not objRecordSet.EOF Then
Debug.Print vbCrLf & vbCrLf & "Second Time..."
While Not objRecordSet.EOF
Debug.Print objRecordSet!Stor_ID
objRecordSet.MoveNext
Wend
End If
objSQLConnection.Close
End Sub
The recordset does not need to be updateable. I'm using SQL Server 2000. Can anyone see what I'm doing wrong?
I created a small program that simulates what I'm doing so that I can try the different options easier than doing it in the actual application. Here's the button event code from my test app. This is all of the code.
Thanks,
Paul
Private Sub Command2_Click()
Dim objCommand As ADODB.Command
Dim objRecordSet As ADODB.Recordset
Dim sSQL As String
Dim objSQLConnection As ADODB.Connection
Set objSQLConnection = New ADODB.Connection
Call objSQLConnection.Open("LocalServer"
Set objCommand = New ADODB.Command
objCommand.ActiveConnection = objSQLConnection
sSQL = sSQL & " Use Pubs SELECT Stor_ID FROM Sales WHERE Stor_ID like '7%'"
objCommand.CommandText = sSQL
Set objRecordSet = New ADODB.Recordset
objRecordSet.CursorLocation = adUseClient
objRecordSet.CursorType = adOpenKeyset
Set objRecordSet = objCommand.Execute
'Simulate loading a grid...
While Not objRecordSet.EOF
Debug.Print objRecordSet!Stor_ID
objRecordSet.MoveNext
Wend
'Set a filter - This is where it's executing the query again
objRecordSet.Filter = "Stor_ID like '70%'"
'Reload the grid
If Not objRecordSet.EOF Then
Debug.Print vbCrLf & vbCrLf & "Second Time..."
While Not objRecordSet.EOF
Debug.Print objRecordSet!Stor_ID
objRecordSet.MoveNext
Wend
End If
objSQLConnection.Close
End Sub