[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Primary Key in MS Access - modify columns programatically

Posted on 2013-06-21
1
Medium Priority
?
270 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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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 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…
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…
Suggested Courses

873 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