[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

creating key fields in remote tables

Posted on 2002-03-16
2
Medium Priority
?
270 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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

649 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