Results 1 to 4 of 4
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    Determine the Primary key within a table using VBA


    Using VBA, how do you determine the Primay key of a table? I'm working with TableDefs, but I can't locate primary key. Thanks in advance!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Bing: VBA finding primary key

    Review http://bytes.com/topic/access/answer...-key-using-vba
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    I found this:
    CurrentDb.TableDefs("MyTable").Indexes("PrimaryKey ").Fields

    This worked.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Nice. I just tested on a table with compound key. It returns all the PK fields as a semi-colon delimited string.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code to determine where a table is in use
    By markjkubicki in forum Programming
    Replies: 2
    Last Post: 07-09-2013, 11:34 AM
  2. Replies: 1
    Last Post: 12-04-2012, 11:46 PM
  3. Replies: 8
    Last Post: 03-22-2012, 08:48 AM
  4. Replies: 18
    Last Post: 07-26-2011, 04:38 AM
  5. table relations & primary key
    By mwabbe in forum Access
    Replies: 9
    Last Post: 08-19-2010, 10:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums