By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,027 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,027 IT Pros & Developers. It's quick & easy.

Crating access tables from vb code

P: 4
I am using TableDefs function to update table fields from vb code but i cant give a field the property Indexed Yes (No Duplicates)
Please help.
Thank you.
Nov 22 '06 #1
Share this Question
Share on Google+
2 Replies


NeoPa
Expert Mod 15k+
P: 31,615
I don't know the answer to this but I expect that rather than changing the field itself, you somehow have to add an index referring to the field (to the Indexes collection).
Nov 22 '06 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
I don't know the answer to this but I expect that rather than changing the field itself, you somehow have to add an index referring to the field (to the Indexes collection).
Exactly right.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim tdf As TableDef
  3. Dim fld As Field
  4. Dim newIndex As Index
  5.  
  6.    Set tdf = CurrentDb.TableDefs("TableName")
  7.    Set newIndex = tdf.CreateIndex("IndexName")
  8.    newIndex.Primary = True 'if primary key
  9.    newIndex.Unique = True ' if unique value, i.e. No Duplicates
  10.    Set fld = newIndex.Fields("FieldName")
  11.    tdf.Indexes.Append newIndex
  12.  
  13.  
Nov 23 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.