Solved

Primary Key in MS Access - modify columns programatically

Posted on 2013-06-21
1
236 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now