I am using ADO. I did set the CursorLocation property to adUseClient and
then
it returns an error of "Current provider does not support the necessary
interface for index functionality". My Seek sub works fine but once I add
the
sort it bombs with that error. All I really need to do is open a table in
the
order it was created (sort by autonumber) because it is a history. Here is
my
module that errors:
Public Sub Dynamic_Update_Recycle_Repair_Counts()
Dim strSQL As String
strSQL = "SELECT [History].* FROM History ORDER BY [Entry #]ASC;"
'Open History recordset.
Dim rsHistory As New ADODB.Recordset
Set cn = CurrentProject.Connection
Set rsHistory = New ADODB.Recordset
With rsHistory
.ActiveConnection = cn
'.Source = strSQL
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.Open strSQL, Options:=adCmdTableDirect
'.Sort = "[Entry #] ASC"
.Index = "Serial Number"
End With
'Open "PCM Interfaces (Main Table) recordset.
Dim rsMainData As New ADODB.Recordset
With rsMainData
.Open "PCM Interfaces (Main Table)", CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic, adCmdTableDirect
.Index = "PrimaryKey"
.MoveFirst
End With
Do Until rsMainData.EOF = True
rsHistory.MoveFirst
'find the last instance,if any, of the current interface and update the
recycle count and repair count
rsHistory.Seek rsMainData("Serial Number"), adSeekLastEQ
If Not rsHistory.EOF Or rsHistory.BOF Then
rsMainData("Recycle Count") = rsHistory("Recycle Count")
rsMainData("Repair Count") = rsHistory("Repair Count")
Else
End If
'Update the current record before moving to the next record
rsMainData.Update
'Move to the next record in the "PCM Interfaces (Main Data)" table.
rsMainData.MoveNext
Loop
rsHistory.MoveFirst
'Close the recordsets
rsMainData.Close
rsHistory.Close
Set rsMainData = Nothing
Set rsHistory = Nothing
End Sub
--
Regards, Michael
Brendan Reynolds said:
Can I open a recordset and Sort it and then Seek in it? I continue to
get
errors due to a error related to the index. My Seek worked fine until I
tried
to add a Sort prior. Should I use a mySQL to open the recordset? Any
examples
would help.
--
Regards, Michael
A DAO recordset? Nope. You can only use Sort with a dynaset-type and
snapshot-type recordsets, and you can only use Seek with table-type
recordsets. To sort a table-type recordset, use the Index property.
See the following on-line help topic ...
http://office.microsoft.com/client/...CESS.DEV&lcid=2057&QueryID=L5wB2Oelr&respos=2
I don't use ADO much, but according to the help file, you can set the
Sort
property of an ADO recordset if you set the CursorLocation property to
adUseClient.
See the following on-line help topic ...
http://office.microsoft.com/client/helppreview.aspx?AssetID=HV012287611033&ns=MSACCESS.DEV&lcid=2057