Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / January 2005

Tip: Looking for answers? Try searching our database.

add index to existing field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jaden - 19 Jan 2005 18:15 GMT
How can I add an index to an existing field using VB?

Thanks!
Allen Browne - 19 Jan 2005 18:35 GMT
This example shows how to programmatically create:
- a primary key index;
- an index on a single field;
- a multi-field index.

Sub CreateIndexesDAO()
   Dim db As DAO.Database
   Dim tdf As DAO.TableDef
   Dim ind As DAO.Index

   'Initialize
   Set db = CurrentDb()
   Set tdf = db.TableDefs("tblContractor")

   '1. Primary key index.
   Set ind = tdf.CreateIndex("PrimaryKey")
   With ind
       .Fields.Append .CreateField("ContractorID")
       .Unique = False
       .Primary = True
   End With
   tdf.Indexes.Append ind

   '2. Single-field index.
   Set ind = tdf.CreateIndex("Inactive")
   ind.Fields.Append ind.CreateField("Inactive")
   tdf.Indexes.Append ind

   '3. Multi-field index.
   Set ind = tdf.CreateIndex("FullName")
   With ind
       .Fields.Append .CreateField("Surname")
       .Fields.Append .CreateField("FirstName")
   End With
   tdf.Indexes.Append ind

   'Refresh the display of this collection.
   tdf.Indexes.Refresh

End Sub

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> How can I add an index to an existing field using VB?
>
> Thanks!
Jaden - 20 Jan 2005 17:45 GMT
Hey Allen -

Works like a charm... I had located the example in Help but I had my syntax
messed up until I saw your reply. Thanks for your assistance.

> This example shows how to programmatically create:
> - a primary key index;
[quoted text clipped - 40 lines]
> >
> > Thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.