Solved

creating key fields in remote tables

Posted on 2002-03-16
2
260 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

808 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