How do I create an index in my table? 
Author Message
 How do I create an index in my table?

How do I create an index in an Access database? I want to first create the
table, then the index and then the second field in the table. Here's what my
table should look like:

* Table name: tblPrograms
* First field in table is the "ID" field which is to be an Autonumber field
with Indexed:=Yes (No Duplicates)
* Second field is to be called "Programs" and to contain text only.

How do I do it?

Here's code that i'm trying to use:

    ' Create the new tblPrograms table.
    Set tblDefNew = dbChoice.CreateTableDef("tblPrograms")
    Set fldAppenNewIndex = tblDefNew.CreateIndex("ID")
    Set fldAppenNewField = fldAppenNewIndex.CreateField("ID", dbLong)
    fldAppenNewIndex.Primary = True
    fldAppenNewIndex.Unique = True
    tblDefNew.Indexes.Append fldAppenNewIndex
    Set fldAppenNewField = tblDefNew.CreateField("Program", dbText)
    tblDefNew.Fields.Append fldAppenNewField
    dbChoice.TableDefs.Append tblDefNew

But I'm getting an error on the last line- "Runtime Error 3264- No field
defined- cannot append TableDef or Index."

I can't understand what I'm doing wrong?

--

Regards

Julian Milano

[Remove "_NOSPAM" to reply]



Wed, 14 Dec 2005 14:07:13 GMT  
 How do I create an index in my table?
Already answered in microsoft.public.access.tablesdbdesign, where you asked
the same question.

If you feel you need to post to more than one group (HINT: it's seldom
necessary), please have the courtesy to cross-post (send the one message to
all groups at once), rather than multi-post (send individual messages to
each group). In this way, all responses to your post will be available
together, regardless of what group the responder was in, and the rest of us
won't have to read your post multiple times. (It also uses fewer server
resources)

I see you're using Outlook Express. Click the "Newsgroups:" label to the
left of the box containing the name of the current newsgroup. That will open
a dialog that will let you add additional newsgroups to your post. Note that
it's generally consider to be A Bad Thing to cross-post to more than about 2
or 3 newsgroups. (In fact, at
http://www.microsoft.com/presspass/features/2001/Mar01/Mar27pmvp.asp
Microsoft suggests that "One group will suffice")

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele


Quote:
> How do I create an index in an Access database? I want to first create the
> table, then the index and then the second field in the table. Here's what
my
> table should look like:

> * Table name: tblPrograms
> * First field in table is the "ID" field which is to be an Autonumber
field
> with Indexed:=Yes (No Duplicates)
> * Second field is to be called "Programs" and to contain text only.

> How do I do it?

> Here's code that i'm trying to use:

>     ' Create the new tblPrograms table.
>     Set tblDefNew = dbChoice.CreateTableDef("tblPrograms")
>     Set fldAppenNewIndex = tblDefNew.CreateIndex("ID")
>     Set fldAppenNewField = fldAppenNewIndex.CreateField("ID", dbLong)
>     fldAppenNewIndex.Primary = True
>     fldAppenNewIndex.Unique = True
>     tblDefNew.Indexes.Append fldAppenNewIndex
>     Set fldAppenNewField = tblDefNew.CreateField("Program", dbText)
>     tblDefNew.Fields.Append fldAppenNewField
>     dbChoice.TableDefs.Append tblDefNew

> But I'm getting an error on the last line- "Runtime Error 3264- No field
> defined- cannot append TableDef or Index."

> I can't understand what I'm doing wrong?

> --

> Regards

> Julian Milano

> [Remove "_NOSPAM" to reply]



Wed, 14 Dec 2005 18:44:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Creating Indexes after Make Table query

2. create unique index while linking server table

3. Can't create index in new table

4. Create an Index USING CODE on existing table

5. Creating an index on a table on a remote database

6. Access 2000 VBA/SQL - cannot create pseudo-index on linked SQL Server table

7. Create Index using SQL in Access 2000 Table

8. Request help creating a multi-field table index

9. HELP with Creating and INDEX on an ACCESS TABLE

10. Create Index on Dbase IV Table?

11. Create Index using SQL in Access 2000 Table

12. Creating Index on a table with variable as name

 

 
Powered by phpBB® Forum Software