Solved

ADODC Control + Index

Posted on 2003-11-26
8
541 Views
Last Modified: 2013-12-25
Hello

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

Thanks

Fabian
0
Comment
Question by:PROMISYS
8 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 9824490
PROMISYS,

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.

Leon
0
 

Author Comment

by:PROMISYS
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 ...
0
 
LVL 29

Assisted Solution

by:leonstryker
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

Leon
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:MYLim
ID: 9830496
0
 
LVL 8

Accepted Solution

by:
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.

'BeginSeekVB
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.
        rst.MoveFirst
        Do While rst.EOF = False
            Debug.Print rst!EmployeeId; ": "; rst!firstname; " "; _
                rst!LastName
            rst.MoveNext
        Loop
   
' Prompt the user for an EmployeeID between 0 and 9.
      rst.MoveFirst
      Do
         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."
            Else
               Debug.Print strID; ": Employee='"; rst!firstname; " "; _
               rst!LastName; "'"
            End If
         End If
      Loop
End If

rst.Close
End Sub
'EndSeekVB

0
 
LVL 8

Expert Comment

by:MYLim
ID: 9830604
http://doc.ddart.net/mssql/sql2000/html/mdacxml/htm/mdproindex.htm
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.

Remarks
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.

0
 
LVL 1

Expert Comment

by:ayufans
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

ayufans
Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now