MDAC 2.5 SDK - ADO


 

Optimize Property Example (VB)

See Also

This example demonstrates the Field object’s dynamic Optimize property. The zip field of the Authors table in the Pubs database is not indexed. Setting the Optimize property to True on the zip field authorizes ADO to build an index that improves the performance of the Find method.

Sub Main()
   OptimizeX
End Sub

Public Sub OptimizeX()
Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient        'Enable index creation
rst.Open "SELECT * FROM Authors", _
         "DSN=Pubs;Provider=MSDASQL;", _
         adOpenStatic, adLockReadOnly, adCmdText
rst!zip.Properties("Optimize") = True   'Create the index
rst.Find "zip = '94595'"                'Find Akiko Yokomoto
Debug.Print rst!au_fname & " " & rst!au_lname & " " & _
         rst!address & " " & rst!city & " " & rst!State
rst!zip.Properties("Optimize") = False  'Delete the index

rst.Close
End Sub