Solved

Primary Key in MS Access - modify columns programatically

Posted on 2013-06-21
1
227 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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 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…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

771 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

16 Experts available now in Live!

Get 1:1 Help Now