?
Solved

No fields defined?

Posted on 1998-05-27
7
Medium Priority
?
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 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