Access still looking for deleted table :( (1 Viewer)

smig

Registered User.
Local time
Today, 07:13
Joined
Nov 25, 2009
Messages
2,209
I have a code to read the PK from tables, and write them to a table where I save the full structure
For some weird reason I get an error that Access can't locate a table (A connected table) I already removed from my db :banghead:

I get an error
Run Time errro 3078
Access can't find the table or query XXXX, make sure it exist and properly spelled

It shouldn't be exist as I alredy removed it from my db :eek:



here is the code I use (I marked where error appear)
Code:
' --- Find PrimaryKey
For Each tdf In CurrDB.TableDefs
    ' If the table has a connect string, it's a linked table.
    If Len(tdf.Connect) > 0 Then
        
        [COLOR="DarkOrange"]For Each idxLoop In tdf.Indexes[/COLOR]
            With idxLoop
                For Each prpLoop In idxLoop.Properties
                    Select Case prpLoop.Name
                        Case "Primary"      ' --- PrimaryKey
                            If prpLoop.Value = True Then
                                hldPrimary = True
                            Else
                                hldPrimary = False
                            End If
                        Case "Unique"        ' --- Unique
                            If prpLoop.Value = True Then
                                hldUnique = True
                            Else
                                hldUnique = False
                            End If
                        Case "IgnoreNulls"        ' --- IgnoreNulls
                            If prpLoop.Value = True Then
                                hldIgnoreNulls = True
                            Else
                                hldIgnoreNulls = False
                            End If
                        Case "Foreign"        ' --- Foreign Key
                            If prpLoop.Value = True Then
                                hldForeign = True
                            Else
                                hldForeign = False
                            End If
                        Case Else
                    End Select
                Next prpLoop
                ' --- Now catch up the Fields that making up this Index
                For Each fldLoop In idxLoop.Fields
                    strSQL = "SELECT * FROM [TablesStructure_Table] " & _
                        "WHERE [TableName] = '" & tdf.Name & "' AND [ColumnName] = '" & fldLoop.Name & "' "
                    Set rs = CurrDB.OpenRecordset(strSQL)
                    With rs
                        rs.MoveFirst
                        rs.Edit
                            If idxLoop.Name = "PrimaryKey" And hldPrimary = True Then
                                rs.Fields("ColumnPrimaryKey") = True
                            End If
                        rs.Update
                    End With
                    rs.Close
                Next fldLoop
            End With
        Next idxLoop
    End If
Next tdf
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:13
Joined
May 7, 2009
Messages
19,243
the tabledef of the deleted table is still exists with prefix "~". so test the first string of the tabledef name if it is "~" (Left(tdt, 1)="~"), and ignore it inside the If clause.
 

smig

Registered User.
Local time
Today, 07:13
Joined
Nov 25, 2009
Messages
2,209
Thanks for the quick help

Compacting did the job :)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:13
Joined
May 7, 2009
Messages
19,243
in the future, if you are unable to compact your db, try changing this code to:

If Len(tdf.Connect) > 0 And Left(tdf.Name , 1) <> "~" Then
...
...
 

smig

Registered User.
Local time
Today, 07:13
Joined
Nov 25, 2009
Messages
2,209
in the future, if you are unable to compact your db, try changing this code to:

If Len(tdf.Connect) > 0 And Left(tdf.Name , 1) <> "~" Then
...
...
Will change it as suggested [emoji4]

Sent from my Redmi Note 4 using Tapatalk
 

Users who are viewing this thread

Top Bottom