ADODC Control + Index

Posted on 2003-11-26
Last Modified: 2013-12-25

Is It possible to change the Index of a table wich is linked to an ADODC control ?
If yes, how can I change it ?


Question by:PROMISYS
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 29

Expert Comment

ID: 9824490

It should be possible, but not by using ADODC.  What database are you using in the backend?  

May I suggest you not use ADODC at all.  It will make your life a lot easier.


Author Comment

ID: 9824884
It's an Access Database.

I first try to use DAO but, I got some problems when
more than one user use the program ...
LVL 29

Assisted Solution

leonstryker earned 200 total points
ID: 9824914
The way to go is by using ADO directly.

Remove the control.  Declare a Connection object (globally) and Recordset object (locally)

Public cnConn As ADODB.Connection

Dim rsRecSet As ADODB.Recordset

You may then bind your recordset to whatever you want such as:

Set dgrGrid.DataSource = rsRecSet

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

MYLim earned 200 total points
ID: 9830601
Seek Method and Index Property Example (VB)
This example uses the Recordset object's Seek method and Index property in conjunction with a given Employee ID, to locate the employee's name in the Employees table of the Nwind.mdb database.

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

Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open "employees", _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=E:\Program Files\Microsoft Office\Office\Samples\northwind.mdb;" & _
            "user id=admin;password=;", _
            adOpenKeyset, adLockReadOnly, adCmdTableDirect

' Does this provider support Seek and Index?
If rst.Supports(adIndex) And rst.Supports(adSeek) Then
    rst.Index = "PrimaryKey"
    ' Display all the employees.
        Do While rst.EOF = False
            Debug.Print rst!EmployeeId; ": "; rst!firstname; " "; _
' Prompt the user for an EmployeeID between 0 and 9.
         strID = LCase(Trim(InputBox(strPrompt, "Seek Example")))
         ' Quit if strID is a zero-length string (CANCEL, null, etc.)
         If Len(strID) = 0 Then Exit Do
         If Len(strID) = 1 And strID >= "0" And strID <= "9" Then
            rst.Seek Array(strID), adSeekFirstEQ
            If rst.EOF Then
               Debug.Print "Employee not found."
               Debug.Print strID; ": Employee='"; rst!firstname; " "; _
               rst!LastName; "'"
            End If
         End If
End If

End Sub


Expert Comment

ID: 9830604
ADO API Reference  

Index Property
Indicates the name of the index currently in effect for a Recordset object.

Settings and Return Values
Sets or returns a String value, which is the name of the index.

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 either 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 WillChangeRecordset or RecordsetChangeComplete event handler.
If the Recordset is still executing an operation (which can be determined by the State property).
If a filter has been set on the Recordset with the Filter property.
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.

If the index can be set, the current row position may change. This will cause an update to the AbsolutePosition property, and the generation of WillChangeRecordset, RecordsetChangeComplete, WillMove, and MoveComplete events.

If the index can be set and the LockType property is adLockPessimistic or adLockOptimistic, then an implicit UpdateBatch operation is performed. This releases the current and affected groups. Any existing filter is released, and the current row position is changed to the first row of the reordered Recordset.

The Index property is used in conjunction with the Seek method. If the underlying provider does not support the Index property, and thus the Seek method, consider using the Find method instead. Determine whether the Recordset object supports indexes with the Supports(adIndex) method.

The built-in Index property is not related to the dynamic Optimize property, although they both deal with indexes.


Expert Comment

ID: 10512129
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points split between leonstryker and MYLim

Please leave any comments here within the next four days.


Cleanup Volunteer

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question