Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Still Index error 1

Status
Not open for further replies.

121410

Programmer
Jun 6, 2001
5
VN
Now my Code is

Code:
Set cn = new ADODB.Connection
Set rs = new ADODB.Recordset

With cn
    .ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "myDatabase.mdb"
     .Open
End With
     
rs.Open "Select * from myTable",cn, adOpenDynamic, adLockOptimistic
rs.Index = "myField"

When run above code, error " Member or data member not found" still occur at "Index" property

Can you tell me why?
 
From ADO Help:


The index named by the Index property must have previously been declared on the base table underlying the Recordset object. That is, the index must have been declared programmatically as an ADOX Index object, or when the base table was created.

A run-time error will occur if the index cannot be set. The Index property cannot be set within a WillRecordsetChange or RecordsetChangeComplete event handler. Nor can it be set if the Recordset is still executing an operation. The Index property can always be set successfully if the Recordset is closed, but the Recordset will not open successfully, or the index will not be usable, if the underlying provider does not support indexes.

Example:

Sub CreateIndex()
Dim tbl As New Table
Dim idx As New ADOX.Index
Dim cat As New ADOX.Catalog

'Open the catalog.
' Open the Catalog.
cat.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\" & _
"Office\Samples\Northwind.mdb;"

' Define the table and append it to the catalog
tbl.Name = "MyTable"
tbl.Columns.Append "Column1", adInteger
tbl.Columns.Append "Column2", adInteger
tbl.Columns.Append "Column3", adVarWChar, 50
cat.Tables.Append tbl

' Define a multi-column index
idx.Name = "multicolidx"
idx.Columns.Append "Column1"
idx.Columns.Append "Column2"

' Append the index to the table
tbl.Indexes.Append idx

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top