Hi

In vb i get error 3015 where it says idx(field name) isn't an index in this table. Look in the Indexes Collection of the Tabledef object to determine the valid index names.

I have Access97 database and checked that the field i mentioned is indexed(Autonumber).
I get error on the Redline given below.

Can anybody help on this please.

Private Sub Form_Load()
'------------------------------------------------------------------------

CenterForm Me

OpenhrDatabase

Set mobjCandRst = gobjhrDB.OpenRecordset("Candidate", dbOpenTable)
mobjCandRst.Index = "idxcandidpk"

mblnOKToExit = True

cmdFirst_Click

End Sub

Dani AI

Generated

Nice that found the fix — for anyone who hits the same runtime 3015 later, the error basically means the index name you tried to use cannot be found or used on the recordset you opened. Common causes are: the index name is different than you expect, the table is actually a query/linked table (no usable TableDef indexes), the recordset type isn’t a table-type, or the code is using the wrong data library.

A quick, reliable first check is to list the table’s Indexes collection so you see the exact names the engine expects. For DAO, example enumeration:

Dim db As DAO.Database
Dim td As DAO.TableDef
Dim ix As DAO.Index

Set db = DBEngine.Workspaces(0).Databases(0)   'or use your own DB variable
Set td = db.TableDefs("YourTableName")

For Each ix In td.Indexes
    Debug.Print ix.Name, ix.Fields.Count
Next ix

If the expected name isn’t shown, don’t set the recordset’s Index to it. If the table is linked or you can’t use a table-type recordset, use a standard lookup instead (safer and works for dynasets/queries):

Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("YourTableName", dbOpenDynaset)
rs.FindFirst "IDField = " & someKey
If Not rs.NoMatch Then
    ' record found
End If

Quick checklist: confirm you’re using DAO (correct reference/version), enumerate TableDef.Indexes to get the true index names, remember Seek/Index apply only to table-type recordsets, and consider compact/repair if indexes appear corrupted or missing. These steps explain why the name mismatch gives 3015 and how to find the exact index name so the problem doesn’t recur.

Solved the bug by myself...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.