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 SandilandsOP
@Reply 4 years ago
Should have know - Security Part 2 solves this. Sorry for my impatience :)
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access SQL Server Lessons.