Add field to index thru DAO 
Author Message
 Add field to index thru DAO

Hi Michael,

You need to delete the old index and then create a new one with the
same name and add the fields to it. You cannot just add a field to an
existing index. Don't ask me why <g>.

Something like this:

Dim db As Database
Dim MyDef As TableDef
Dim MyIdx As Index
Dim Myfld As Field
Set db = CurrentDb
Set MyDef = db.TableDefs("MyTable")
MyDef.Indexes.Delete ("MyIndex")
Set MyIdx = MyDef.CreateIndex("MyIndex")
Set Myfld = MyIdx.CreateField("MyTextField", dbText, 50)
MyIdx.Fields.Append Myfld
Set Myfld = myIdx.CreateField("longfield", dbLong)
MyIdx.Fields.Append Myfld
MyDef.Indexes.Append MyIdx

 -- Andy

Quote:
>Has anyone tried adding a field to an index programatically thru DAO
>before? I have written the following code to do so, but it will not append
>the field correctly (Invalid Operation error occurrs):

>    Set myidx = MyDef.Indexes("JOB_NUM")
>    Set myfield = myidx.CreateField("SEQ_NO")
>    myidx.Fields.Append myfield

>There is a field in the table called SEQ_NO, and it is an integer. What am
>I doing wrong here?

>Thanks!!
>--
>Michael W. Shrader
>TechLore Solutions
>Houston, TX



Sat, 23 Oct 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Add field to index thru DAO

2. Adding Field to Access db - need to make indexed property of field No Duplicates

3. Too many indexes - Wierd hidden indexes preventing index add

4. remove index from field or delete a indexed field

5. DAO and Adding Index to a Table

6. Auto Add Date In Memo Field Thru VB5

7. Indexing a new field with DAO

8. Adding fields to a table and index

9. Create Index without adding field!!!

10. I can't add a key (index) on two fields using VB

11. add autonumber field to table using DAO

12. Add Field via DAO - Set Format Property

 

 
Powered by phpBB® Forum Software