victorlong
asked on
No fields defined?
Why the last line in the following code causes error:
No fields defined - cannot append Tabledef of Index.
Set NewDB = CreateDatabase("c:\tem\try .mdb", dbLangGeneral)
Set NewTbl = NewDB.CreateTableDef("tabl e1")
Set Ind1 = NewTbl.CreateIndex("index1 ")
Ind1.Primary = True
Set F1 = Ind1.CreateField("field1")
Ind1.Fields.Append F1
NewTbl.Indexes.Append Ind1
NewDB.TableDefs.Append NewTbl
No fields defined - cannot append Tabledef of Index.
Set NewDB = CreateDatabase("c:\tem\try
Set NewTbl = NewDB.CreateTableDef("tabl
Set Ind1 = NewTbl.CreateIndex("index1
Ind1.Primary = True
Set F1 = Ind1.CreateField("field1")
Ind1.Fields.Append F1
NewTbl.Indexes.Append Ind1
NewDB.TableDefs.Append NewTbl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
victorlong,
Set F1 = Ind1.CreateField("field1") only create a field to the index object, and it does not create it to your table, that's why you have the error.
To create Index, I would use
Set Ind1 = NewTbl.CreateIndex("Field1 ")
Ind1.Primary = True
Ind1.Unique = True ' if You want to
regards
Dalin
Set F1 = Ind1.CreateField("field1")
To create Index, I would use
Set Ind1 = NewTbl.CreateIndex("Field1
Ind1.Primary = True
Ind1.Unique = True ' if You want to
regards
Dalin
ASKER
Hi Dalin.
Getting confused....I think an example may be more helpful. Can you add something or change something in the following code so that the database NewDB can be used? Many thanks.
Set NewDB = CreateDatabase("c:\tem\try .mdb", dbLangGeneral)
Set NewTbl = NewDB.CreateTableDef("tabl e1")
Set Ind1 = NewTbl.CreateIndex("index1 ")
Ind1.Primary = True
Set F1 = Ind1.CreateField("field1")
Ind1.Fields.Append F1
NewTbl.Indexes.Append Ind1
Getting confused....I think an example may be more helpful. Can you add something or change something in the following code so that the database NewDB can be used? Many thanks.
Set NewDB = CreateDatabase("c:\tem\try
Set NewTbl = NewDB.CreateTableDef("tabl
Set Ind1 = NewTbl.CreateIndex("index1
Ind1.Primary = True
Set F1 = Ind1.CreateField("field1")
Ind1.Fields.Append F1
NewTbl.Indexes.Append Ind1
victorlong,
Sorry that I was not able to get back to you yesterday.
Which version of VB are you working with?
Sorry that I was not able to get back to you yesterday.
Which version of VB are you working with?
ASKER
Hi Dalin.
I think I understan now....that is not my fault :-)
I always thought
Set F1 = Ind1.CreateField("field1")
is "create" a field. In fact it just tell VB that a field has an index. The field may existed before above code!
In English, "create" means something is bringed to the world but before "create" it not existed.....
This time I may confuse you :-)
I think I understan now....that is not my fault :-)
I always thought
Set F1 = Ind1.CreateField("field1")
is "create" a field. In fact it just tell VB that a field has an index. The field may existed before above code!
In English, "create" means something is bringed to the world but before "create" it not existed.....
This time I may confuse you :-)
victorlog,
You need to "create" the field for both TableDef and Index..
I am sorry that I was not more clear about it. Glad you get it.
If you have additional questions, let me know. I will try my best to be more prompt (I was mostly out of my office yesterday).
Good luck in your project.
Dalin
You need to "create" the field for both TableDef and Index..
I am sorry that I was not more clear about it. Glad you get it.
If you have additional questions, let me know. I will try my best to be more prompt (I was mostly out of my office yesterday).
Good luck in your project.
Dalin
ASKER
> Your Set F1 = Ind1.CreateField("field1")
> should be
> Set F1 = NewTb1.CreateField("field1
> NewTb1.Fields.Append F1
That is came from a book! I will check again though.
But, if we change the line, how can VB know "field1" has "index1"?