473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to add index with CreateIndex ?

The last 4 lines seem to be screwing up.... any suggestions welcome!

- - - - - - - - - - - - - -
Dim db As Database
Dim tdf As TableDef
Dim idxPk As Index
Dim idxFld As Field

Set tdf = db.CreateTableDef("tblAppointments") 'create new table
With tdf 'add fields
.Fields.Append .CreateField("ApptDate", dbDate)
.Fields.Append .CreateField("Subject", dbText, 100)
.Fields("Subject").AllowZeroLength = True
.Fields.Append .CreateField("Entity_ID", dbLong)
.Fields.Append .CreateField("Appt_ID", dbLong)
.Fields("Appt_ID").Attributes = dbAutoIncrField
End With
Set idxPk = tdf.CreateIndex("Appt_ID") 'make Appt_ID primary key
idxPk.Primary = True
idxPk.Unique = True
Set idxFld = idxPk.CreateField("Appt_ID") 'type mismatch here...
idxPk.Fields.Append idxFld 'add field to Fileds collection of index
object - this screws up, too...
tdf.Indexes.Append idxPk 'add index to index collection 'have not got
far enough to validate these nex lines...
db.TableDefs.Append tdf 'append tdf to TablsDefs collection

- - - - - - - - - - - -

What I'm trying to do is create a table programmatically and add a Primary
Key, and also perhaps another non-unique index.... if I can get the Primary
key first.... I read somewhere that I might need a separate tableDef to
create the PK???
Nov 12 '05 #1
2 15547
Ah ha...

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim idxPk As DAO.Index
Dim idxFld As DAO.Field

Apparently Access has an identity crisis when it comes to data access...

"deko" <dj****@hotmail.com> wrote in message
news:H5*******************@newssvr29.news.prodigy. com...
The last 4 lines seem to be screwing up.... any suggestions welcome!

- - - - - - - - - - - - - -
Dim db As Database
Dim tdf As TableDef
Dim idxPk As Index
Dim idxFld As Field

Set tdf = db.CreateTableDef("tblAppointments") 'create new table
With tdf 'add fields
.Fields.Append .CreateField("ApptDate", dbDate)
.Fields.Append .CreateField("Subject", dbText, 100)
.Fields("Subject").AllowZeroLength = True
.Fields.Append .CreateField("Entity_ID", dbLong)
.Fields.Append .CreateField("Appt_ID", dbLong)
.Fields("Appt_ID").Attributes = dbAutoIncrField
End With
Set idxPk = tdf.CreateIndex("Appt_ID") 'make Appt_ID primary key
idxPk.Primary = True
idxPk.Unique = True
Set idxFld = idxPk.CreateField("Appt_ID") 'type mismatch here...
idxPk.Fields.Append idxFld 'add field to Fileds collection of index
object - this screws up, too...
tdf.Indexes.Append idxPk 'add index to index collection 'have not got
far enough to validate these nex lines...
db.TableDefs.Append tdf 'append tdf to TablsDefs collection

- - - - - - - - - - - -

What I'm trying to do is create a table programmatically and add a Primary
Key, and also perhaps another non-unique index.... if I can get the Primary key first.... I read somewhere that I might need a separate tableDef to
create the PK???

Nov 12 '05 #2
No "identity crisis", just two "data access methods" which happen to share
some object names but are not compatible. It's a long story, told before,
and could be googled up, I'd wager.

"deko" <dj****@hotmail.com> wrote in message
news:3g*******************@newssvr25.news.prodigy. com...
Ah ha...

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim idxPk As DAO.Index
Dim idxFld As DAO.Field

Apparently Access has an identity crisis when it comes to data access...

"deko" <dj****@hotmail.com> wrote in message
news:H5*******************@newssvr29.news.prodigy. com...
The last 4 lines seem to be screwing up.... any suggestions welcome!

- - - - - - - - - - - - - -
Dim db As Database
Dim tdf As TableDef
Dim idxPk As Index
Dim idxFld As Field

Set tdf = db.CreateTableDef("tblAppointments") 'create new table
With tdf 'add fields
.Fields.Append .CreateField("ApptDate", dbDate)
.Fields.Append .CreateField("Subject", dbText, 100)
.Fields("Subject").AllowZeroLength = True
.Fields.Append .CreateField("Entity_ID", dbLong)
.Fields.Append .CreateField("Appt_ID", dbLong)
.Fields("Appt_ID").Attributes = dbAutoIncrField
End With
Set idxPk = tdf.CreateIndex("Appt_ID") 'make Appt_ID primary key
idxPk.Primary = True
idxPk.Unique = True
Set idxFld = idxPk.CreateField("Appt_ID") 'type mismatch here...
idxPk.Fields.Append idxFld 'add field to Fileds collection of index
object - this screws up, too...
tdf.Indexes.Append idxPk 'add index to index collection 'have not got far enough to validate these nex lines...
db.TableDefs.Append tdf 'append tdf to TablsDefs collection

- - - - - - - - - - - -

What I'm trying to do is create a table programmatically and add a Primary Key, and also perhaps another non-unique index.... if I can get the

Primary
key first.... I read somewhere that I might need a separate tableDef to
create the PK???


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jofio | last post by:
Hello, I am a newbie in PHP and I am enthusiastically trying out things. I've just replaced my index.html ( file with index.php
9
by: kosh | last post by:
I was wondering if there is or there could be some way to pass a generator an optional starting index so that if it supported that slicing could be made more efficient. Right now if you do use a...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
2
by: Wendell Cochran | last post by:
I need to be able to set a primary index on a table does anyone have code for this... thanks wendell cochran
1
by: Average Bear | last post by:
If anyone could help with this one, I am a bit puzzled. I understand you can create an index using two fields of a database, then use the seek method to find a record based on both fields. My...
19
by: Lyle Fairfield | last post by:
MSDN Home > MSDN Library > Win32 and COM Development Data Access Microsoft offers many data access technologies to suit various development needs. This section of the MSDN Library contains...
0
by: Owen Jenkins | last post by:
Hi, My application allows users to create a new back end for separate purposes. It does this by using Make Table Queries and Indexing via SQL. For example ... sqlString = "SELECT * INTO " &...
4
by: Owen Jenkins | last post by:
Hi, No-one replied to this when I sent it last week. Any bites out there today?? ----- My application allows users to create a new back end for separate purposes. It does this by using Make...
85
by: Russ | last post by:
Every Python programmer gets this message occasionally: IndexError: list index out of range The message tells you where the error occurred, but it doesn't tell you what the range and the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.