
Please Help!!!! Trouble creating/using dbase III indexes
Hi,
I have 2 questions that all pertain to dBase III files:
1st - How do I create an index on several fields - lets say firstname,
lastname, address, city so that it sorts by firstname first, then lastname,
then address, etc.
2nd - I have a dbase file I'm opening with VB5 and DAO. I need to index on
certain fields for sorting, etc. There are 2 fields in this particular
table: Name and Phone. I wanted to try to order the resultset by the phone
number, so I am trying the following code to index on the phone field. I make
sure that there are not any indexes or other files corresponding to this
database.
Here's my code for opening the file and creating the index.
dim db_phone as database
dim td_phone as tabledef
dim idx_phone as index
dim rs_phone as recordset
strDatapath = "c:\dbase\phone.dbf"
Set db_phone = OpenDatabase(strDataPath, False, False, "Dbase III")
Set td_phone = db_phone.TableDefs("phone")
Set idx_phone = td_phone.CreateIndex("phone")
With idx_phone
.Fields = "phone"
.Primary = True
End With
td_phone.Indexes.Append idx_phone
Set rs_phone = td_phone.OpenRecordset(dbOpenTable)
<loop to pull data>
However, when I go through the recordset, it is still sorted by name. I need
to be able to sort different databases by different fields!
Do I need to re-open the database after the index is created?
Thanks for any help you can give.
--Kent