Solved

Primary Key in MS Access - modify columns programatically

Posted on 2013-06-21
1
251 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
1 Comment
 
LVL 57

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

Suggested Solutions

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…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

809 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