Access/VB code error

G

Guest

Help would be greatly appreciated with the following.

I have created a database with a form and tables. On the
form I have created a test button. The code below
(fragment)is from an example in access (Index Property).
I have pasted this code on my form's code part and the
procedure Seek() is used in my test button procedure.

The problem is that I can't get the Seek() procedure to
work. The following error occurs..
Run-time error '-2147217867 (80040e35)'
EmployeeID is not an index in this table

This database does exist in the given directory. The
employees table does exist and employeeID is a field of
this table with the "key" symbol to the extreme left of
the screen.

How do I interpret the error and where have I gone wrong.



Public Sub SeekX()
Dim rst As ADODB.Recordset
Dim strID As String
Dim strPrompt As String
strPrompt = "Enter an EmployeeID (e.g., 1 to 9)"

Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open "employees", _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft
Office\Office\Samples\northwind.mdb;" & _
"user id=admin;password=;", _
adOpenKeyset, adLockReadOnly,
adCmdTableDirect
' "Data Source=c:\temp\northwind.mdb;" & _
' Does this provider support Seek and Index?
If rst.Supports(adIndex) And rst.Supports(adSeek) Then
rst.Index = "EmployeeID" ******** This is where the
error occurs *************
' Display all the employees.
 
D

Douglas J. Steele

You need to use the name of the index, not the name of the field in the
index

If the key symbol is beside EmployeeId, odds are the Index name is
PrimaryKey. To double check, open the table in Design mode, and select View
| Indexes from the menu bar. The Index Name will be in the left-most column
of the display.
 
G

Guest

Thanks for that, it worked. The example used was that
from the aaccess help. So was there an error in the
coding by MS?
I can now be on my way to discover new stuff. Thanks again
 
D

Douglas J. Steele

Thanks for that, it worked. The example used was that
from the aaccess help. So was there an error in the
coding by MS?

Not necessarily. Indexes can be named whatever you like. If you already had
an index named PrimaryKey and you added a new index based on the EmployeeId,
you may very well choose to name that new index EmployeeId.
 

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