dbTalk Databases Forums  

VBA create multiple fiield indexes

comp.databases.ms-access comp.databases.ms-access


Discuss VBA create multiple fiield indexes in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil
 
Posts: n/a

Default VBA create multiple fiield indexes - 09-19-2010 , 07:21 PM






The code below creates a unique index called MemAddID

With MyTblDef
Set MyField = .CreateField(FieldName, dbLong)
MyField.Required = True
MyField.OrdinalPosition = 0
Fields.Append s.Append MyField ' Add Field "MemAddID" at top of table OK

Set MyIndex = .CreateIndex(FieldName)
Set MyField = MyIndex.CreateField(FieldName)
MyIndex.Required = False
MyIndex.Unique = True ' Don't want this
MyIndex.Fields.Append MyIndex.CreateField(FieldName)
.Indexes.Append MyIndex ' Add Index
End With

What I want is to remove the uniqueness of MemAddID but add a unique index
combination of MemAddID and MemHeadOfHouseID. Simple to do in table design
view, but I need to do it in VBA.

Can anyone please help with the code.

Thanks

Phil

Reply With Quote
  #2  
Old   
Allen Browne
 
Posts: n/a

Default Re: VBA create multiple fiield indexes - 09-19-2010 , 07:32 PM






There are 3 examples in the CreateIndexesDAO() code here:
http://allenbrowne.com/func-DAO.html#CreateIndexesDAO

The 3rd illustrates the process for a multi-field index.
To make it unique as well, just add the line:
.Unique = True
before the End With.

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


"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Quote:
The code below creates a unique index called MemAddID

With MyTblDef
Set MyField = .CreateField(FieldName, dbLong)
MyField.Required = True
MyField.OrdinalPosition = 0
Fields.Append s.Append MyField ' Add Field "MemAddID" at top of table OK

Set MyIndex = .CreateIndex(FieldName)
Set MyField = MyIndex.CreateField(FieldName)
MyIndex.Required = False
MyIndex.Unique = True ' Don't want this
MyIndex.Fields.Append MyIndex.CreateField(FieldName)
.Indexes.Append MyIndex ' Add Index
End With

What I want is to remove the uniqueness of MemAddID but add a unique index
combination of MemAddID and MemHeadOfHouseID. Simple to do in table design
view, but I need to do it in VBA.

Can anyone please help with the code.

Thanks

Phil

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: VBA create multiple fiield indexes - 09-20-2010 , 02:19 AM



On 20/09/2010 01:32:52, "Allen Browne" wrote:
Quote:
There are 3 examples in the CreateIndexesDAO() code here:
http://allenbrowne.com/func-DAO.html#CreateIndexesDAO

The 3rd illustrates the process for a multi-field index.
To make it unique as well, just add the line:
.Unique = True
before the End With.

Thanks Allen

Perfect

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.