Indexing of Recordset not working

G

Guest

I continually get an error involving the indexing of an open recordset. I
don't know what else to say? I have checked over and over and can't figure
out why it doesn't work? The Index exists in the table "Temptube". so why
do I keep getting the "Run-Time error 3251: Operation is not supported for
this type of object? Here is a sample part of my code:

Option explicit:

Set rst2 = dbs.OpenRecordset("Temptube")
rst2.Index = "AddHour"
 
B

Brendan Reynolds

You can only set the Index property on a table-type recordset (and you can't
open a table-type recordset on a linked table) so ...

Public Sub SetIndex()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSourceDatabase As String

'local table
Set db = CurrentDb
Set rst = db.OpenRecordset("Employees", dbOpenTable)
rst.Index = "PrimaryKey"
'do something here
rst.Close

'linked table
strSourceDatabase = CurrentDb.TableDefs("Employees2").Connect
strSourceDatabase = Mid$(strSourceDatabase, InStr(1, strSourceDatabase,
"=") + 1)
Set db = DBEngine.OpenDatabase(strSourceDatabase)
Set rst = db.OpenRecordset("Employees", dbOpenTable)
rst.Index = "PrimaryKey"
'do something here
rst.Close
db.Close

End Sub
 
P

Pat Hartman\(MVP\)

I find it more efficient to create a query that retrieves ONLY the records I
need. This method works regardless of what type of table or query I need to
process and in most cases is more efficient.
 

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