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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing Table Links in Code

Status
Not open for further replies.

Rohdem

Programmer
Sep 20, 2000
553
US
Is there a way to remove table links using code? I would like to write a procedure in a front end that disconnects all users from the back end of the database, let's me compact and repair the back end, and then relinks to the front end to the back end.

Thanks [sig][/sig]
 
send me an email and I will send you something that works. I need to reboot my computer into a different OS to get at those files. [sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Hi,
Here is a snippet of code directly from the help files in Access. You can view this code by going to help and typing &quot;Relation object&quot; into the &quot;Index&quot; tab's text box. View this topic, then choose example and look at the Microsoft Access code. This code includes the delete method.

Sub NewRelation()
Dim dbs As Database
Dim fld As Field, rel As Relation

' Return reference to current database.
Set dbs = CurrentDb
' Find existing EmployeesOrders relation.
For Each rel In dbs.Relations
If rel.TABLE = &quot;Employees&quot; And rel.ForeignTable = &quot;Orders&quot; Then
' Prompt user before deleting relation.
If MsgBox(rel.Name & &quot; already exists. &quot; & vbCrLf _
& &quot;This relation will be deleted and re-created.&quot;, vbOK) = vbOK Then

dbs.Relations.Delete rel.Name
' If user chooses Cancel, exit procedure.
Else
Exit Sub
End If
End If
Next rel
' Create new relationship and set its properties.
Set rel = dbs.CreateRelation(&quot;EmployeesOrders&quot;, &quot;Employees&quot;, &quot;Orders&quot;)
' Set Relation object attributes to enforce referential integrity.
rel.Attributes = dbRelationDeleteCascade + dbRelationUpdateCascade
' Create field in Fields collection of Relation object.

Set fld = rel.CreateField(&quot;EmployeeID&quot;)
' Provide name of foreign key field.
fld.ForeignName = &quot;EmployeeID&quot;
' Append field to Relation object and Relation object to database.
rel.Fields.Append fld
dbs.Relations.Append rel
MsgBox &quot;Relation '&quot; & rel.Name & &quot;' created.&quot;
Set dbs = Nothing
End Sub

CCTC1
Rob Marriott
rob@career-connections.net [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top