Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access SQL Server Lessons    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Primary Key gone after Relink
Doug Sandilands 
      
4 years ago
In one of my databases where I used the table relink my records became non-updateable after running it - which I figured out was because the primary key was gone from all the tables. If I manually relinked with the odbc external data wizard or by right clicking each linked table - refreshing the link and setting the primary key - it all works fine again.

I searched google / the troubleshooter and was hoping I had it solved with the code below - but while that looked promsing and caused no errors - the primary keys are not set after running the relinktable sub.

The change I made to the RelinkTable sub here is passing both the tablename and the tableindex (RelinkTable("VesselT", "VesselID"), for example) and then setting the VesselID field as the index (see below). I followed the process with msgboxes, the debugger - stepping into each line -  and the always helpful status sub ->  I get no errors, it appears the TableIndex is updated, but when you look at each table, there's still no primary key and my records are not updateable. Any ideas would be appreciated. Thanks very much, Doug

Private Sub RelinkTable(TableName As String, TableIndex As String)

    Dim db As Database, td As TableDef
    Dim idx As Index
    Dim temp As String

    status "Relinking " & TableName &"  with primarykey: "&TableIndex
    
    Set db = CurrentDb()

   ' delete tables if they exist
    On Error Resume Next
       db.TableDefs.Delete (TableName)
    On Error GoTo 0

     Set td = db.CreateTableDef(TableName)

    ' append the table from the server
    td.Connect = TempVars("SQLConnectString")
    td.SourceTableName = TableName
    db.TableDefs.Append td

    ' set the index / as primary key
    Set idx = td.CreateIndex(TableIndex)
    With idx
        .Name = TableIndex
        .Primary = True
        .Required = True
        .IgnoreNulls = False

    End With
End Sub
Doug Sandilands OP  @Reply  
      
4 years ago
Should have know - Security Part 2 solves this. Sorry for my impatience :)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access SQL Server Lessons.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 10:52:41 AM. PLT: 0s