Solved

creating key fields in remote tables

Posted on 2002-03-16
2
263 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
[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
2 Comments
 
LVL 12

Accepted Solution

by:
Paurths earned 100 total points
ID: 6873686
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
ID: 6875026
Spot on, Ricky, good work.

Rick
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSMA Access BE Linked Table Migration Linking Issue 2 41
Google drive Permission Error 43 49
MS Access Query Question 2 36
Convert VBA UDF to SQl SERVER UDF 4 50
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
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…

733 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