Creat index to use it in VBasic6

P

pantelis

I'm trying to find a record in an access table
using VBasic and every time that i clic on find button
appears the following message:
"run-time error 3251"
'this function is not supported for this kind of object'.

Any help it will be appreciated.
 
B

Brendan Reynolds

It would be easier to help you if you posted the code. My guess is that you
may be trying to do something with the wrong type of recordset. As you've
mentioned using an index, possibly you might be trying to set the Index
property of a recordset that is not a table-type recordset. But without
seeing the code, that's just a guess.
 
P

pantelis

This is the code that i wrote in vb.

NAME.Recordset.Index = "ÃÃÑÃÓÔÃÔÉÊÃ"
NAME.Recordset.Seek "=", SeachStr$
If NAME.Recordset.NoMatch Then
NAME.Recordset.MoveFirst
End If

Ο χÏήστης "Brendan Reynolds" έγγÏαψε:
 
B

Brendan Reynolds

Index and Seek only work with table-type recordsets. You haven't shown the
code that sets the properties of the recordset, but almost certainly you are
not opening a table-type recordset. For example ...

This works - recordset is table-type ...

Private Sub CommandButton1_Click()

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

Set db = DBEngine.OpenDatabase("C:\DSDATA\db86.mdb")
Set rst = db.OpenRecordset("tblTest", dbOpenTable)
rst.Index = "PrimaryKey"
rst.Seek "=", 5
MsgBox rst.Fields("TestText")
rst.Close
db.Close

End Sub

This doesn't work - recordset is not table-type ...

Private Sub CommandButton2_Click()

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

Set db = DBEngine.OpenDatabase("C:\DSDATA\db86.mdb")
Set rst = db.OpenRecordset("SELECT * FROM tblTest")
rst.Index = "PrimaryKey"
rst.Seek "=", 5
MsgBox rst.Fields("TestText")
rst.Close
db.Close

End Sub
 
P

pantelis

This is the code that i have to write
at the button of find in vb if i understand it well.
"tbltest" is the name of the table ; ; ; ;
Thank you very much for your help
 
B

Brendan Reynolds

I'm afraid we seem to be having difficulties communicating. You need to
either open the recordset as a table-type recordset, as in the first example
in my previous post, or if for some reason you can't do that you'll need to
use FindFirst instead of Seek.
 
Top