Solved

Primary Key in MS Access - modify columns programatically

Posted on 2013-06-21
1
260 Views
Last Modified: 2013-10-22
I was given a database that needs to have a lkarge number of tables and columns altered to make certain fields on each table primary keys.

If I have a query thatn includes  the structure below is there a simple programatic way to read that query and alter each table/co9lumn to make keys?

table_name         column_name
1                                a
2                                x
2                                y
2                                z
0
Comment
Question by:hwassinger
[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
1 Comment
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39266298
Sub CreateIndexX2()

    Dim dbs As Database

    ' Modify this line to include the path to Northwind
    ' on your computer.
    Set dbs = OpenDatabase("Northwind.mdb")

    ' Create a unique index, PrimaryKey, on the
    ' CustomerID field.
    dbs.Execute "CREATE INDEX PrimaryKey " _
        & "ON Customers (CustomerID) " _
        & "WITH PRIMARY;"

    dbs.Close

End Sub

http://msdn.microsoft.com/en-us/library/office/bb177891(v=office.12).aspx

Jim.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

690 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