Solved

creating key fields in remote tables

Posted on 2002-03-16
2
258 Views
Last Modified: 2012-08-14
In Access 2K, I am creating tables in code.  The tables reside in the 'back end' database.  I have no trouble creating or attaching the tables.  I am having trouble creating the primary indexes.  The error I get is "Can't create index in linked tables."

I am creating the fields using the .createFields construct.  Two questions:  How do I specify an autonumber type (there is no dbAutoNumber constant), and how do I create a two field primary key in a remote db?

Thanks

Rick
0
Comment
Question by:rtstannard
2 Comments
 
LVL 12

Accepted Solution

by:
Paurths earned 100 total points
Comment Utility
hi rtstannard,

here is an example.
This will create the following table;
lngID --> autonumber
lngOther --> numeric
ATextField --> text
AMemoField --> memo

joinindex --> indexname for these fields: lngID and lngOther, and a two-field-primary key


Dim dbs As DAO.Database
Dim tdf As TableDef
Dim fld As Field
Dim idxTwoFields As Index

 Set dbs = CurrentDb
 Set tdf = dbs.CreateTableDef("Mytable")
 
 Set fld = tdf.CreateField("lngID", dbLong)
 fld.Attributes = fld.Attributes + dbAutoIncrField
 
 tdf.Fields.Append fld
 Set fld = tdf.CreateField("lngOther", dbLong)
 tdf.Fields.Append fld
 Set fld = tdf.CreateField("ATextField", dbText)
 tdf.Fields.Append fld
 Set fld = tdf.CreateField("AMemoField", dbMemo)
 tdf.Fields.Append fld
 
 Set idxTwoFields = tdf.CreateIndex("JoinIndex")

    With idxTwoFields
        .Fields.Append .CreateField("lngID")
        .Fields.Append .CreateField("lngOther")
        .Primary = True
    End With
    tdf.Indexes.Append idxTwoFields

 dbs.TableDefs.Append tdf
 
 Set dbs = Nothing


cheers
Ricky
0
 

Author Comment

by:rtstannard
Comment Utility
Spot on, Ricky, good work.

Rick
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

11 Experts available now in Live!

Get 1:1 Help Now