F
FP1
Hello,
I need to repeatedly copy an existing access/jet database and delete
some tables from it using ADODB and ADOX. (I'm linking to backend
databases) It has many relationships defined, which I need to sever (it
just wasn't working out) .
When I try to delete from the Keys collection, I get:
cannot delete this index or table. it is either the primary index or it
used in a relationship.
when I try to delete from Indexes collection, I get:
cannot delete this index or table. it is either the primary index or it
used in a relationship.
When I try to delete the table I get:
cannot delete this index or table. it is either the primary index or it
used in a relationship.
(I tried sql drop and alter, same results.)
I know SOMEBODY must have done this before! What's the secret?
code below. Thank you kindly for you help!
-----
Set tbl = cat.Tables(rs("table_name").Value)
'delete the keys first
Dim keysx As ADOX.keys
Set keysx = cat.Tables(tbl.name).keys
For kx = 0 To keysx.Count - 1
Debug.Print "dropping key " & keysx(kx).name
'cat.Tables(tbl.name).keys.Delete keysx(kx).name
Dim drop
cat.Tables(tbl.name).keys.Delete keysx(kx).name
'drop = "alter table " & tbl.name & " Drop constraint " & keysx
(kx).name
indb.Execute drop
Next
'delete the indexes
Dim indx As ADOX.Indexes
Set indx = cat.Tables(tbl.name).Indexes
For ix = 0 To indx.Count - 1
Debug.Print "dropping index " & indx(ix).name
cat.Tables(tbl.name).Indexes.Delete indx(ix).name
Next
cat.Tables.Delete (rs.Fields.Item("table_name"))
Debug.Print "dropping table " & rs("table_name")
GoTo next_tbl
tbl_error:
Debug.Print "Error deleting table " & Err.Description
next_tbl:
rs.MoveNext
Wend
I need to repeatedly copy an existing access/jet database and delete
some tables from it using ADODB and ADOX. (I'm linking to backend
databases) It has many relationships defined, which I need to sever (it
just wasn't working out) .
When I try to delete from the Keys collection, I get:
cannot delete this index or table. it is either the primary index or it
used in a relationship.
when I try to delete from Indexes collection, I get:
cannot delete this index or table. it is either the primary index or it
used in a relationship.
When I try to delete the table I get:
cannot delete this index or table. it is either the primary index or it
used in a relationship.
(I tried sql drop and alter, same results.)
I know SOMEBODY must have done this before! What's the secret?
code below. Thank you kindly for you help!
-----
Set tbl = cat.Tables(rs("table_name").Value)
'delete the keys first
Dim keysx As ADOX.keys
Set keysx = cat.Tables(tbl.name).keys
For kx = 0 To keysx.Count - 1
Debug.Print "dropping key " & keysx(kx).name
'cat.Tables(tbl.name).keys.Delete keysx(kx).name
Dim drop
cat.Tables(tbl.name).keys.Delete keysx(kx).name
'drop = "alter table " & tbl.name & " Drop constraint " & keysx
(kx).name
indb.Execute drop
Next
'delete the indexes
Dim indx As ADOX.Indexes
Set indx = cat.Tables(tbl.name).Indexes
For ix = 0 To indx.Count - 1
Debug.Print "dropping index " & indx(ix).name
cat.Tables(tbl.name).Indexes.Delete indx(ix).name
Next
cat.Tables.Delete (rs.Fields.Item("table_name"))
Debug.Print "dropping table " & rs("table_name")
GoTo next_tbl
tbl_error:
Debug.Print "Error deleting table " & Err.Description
next_tbl:
rs.MoveNext
Wend