Solved

No fields defined?

Posted on 1998-05-27
7
348 Views
Last Modified: 2010-05-03
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("table1")
    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
0
Comment
Question by:victorlong
  • 4
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
ID: 1461810
victorlong,
Your Set F1 = Ind1.CreateField("field1")
should be
Set F1 = NewTb1.CreateField("field1")
NewTb1.Fields.Append F1  

Regards
Dalin
0
 

Author Comment

by:victorlong
ID: 1461811
Hi Dalin.

>   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"?  
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1461812
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

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:victorlong
ID: 1461813
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("table1")
 Set Ind1 = NewTbl.CreateIndex("index1")
 Ind1.Primary = True
 Set F1 = Ind1.CreateField("field1")
 Ind1.Fields.Append F1
 NewTbl.Indexes.Append Ind1
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1461814
victorlong,
Sorry that I was not able to get back to you yesterday.
Which version of VB are you working with?
0
 

Author Comment

by:victorlong
ID: 1461815
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 :-)
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1461816
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
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now