Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any one know how to delete relationship through a module or macros

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to import table but first it deletes the table than import the table. There are relationship on the database. I want it to delete the relationship before it imports the table throught a macros. Does anyone know how this could be done or even if it can be done.

tig[puppy]
 
I'm not exactly certain what you're attempting. If you want to delete a table and any existing relationships it may have, you can use this:

Function DeleteTable(tName As String)
' This procedure deletes specified table and any
' existing relationships the table is participating
' in. Used mainly for temporary or on-the-fly tables.
' Used inappropriately, it will have a devastating
' effect on an application.

Dim test As String, dbs As Database
Dim found As Boolean, thisrel As Relation
Set dbs = CurrentDb

On Error Resume Next
'**********
'Does table tName exist?
'If true, delete it;
'**********
found = False
test = dbs.TableDefs(tName).Name
If Err <> 3265 Then
found = True
'**********
' Since the delete action will fail if the
' table is participating in any relation, first
' find and delete existing relations for table.
'**********
For Each thisrel In dbs.Relations
If thisrel.Table = tName Or thisrel.ForeignTable = tName Then
dbs.Relations.Delete thisrel.Name
End If
Next thisrel
'**********
' Now, we're ready to delete the table.
'**********
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, tName
DoCmd.SetWarnings True
End If
dbs.Close
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top