Hi,
I want to use the code below to read the relationships in one database and recreate them in another database.
Everything appears to be fine until it reaches the ThisDB.Relations.Append NewRel line, at which point I get an error message "You do not have the necessary permissions to use the '<tablename>' object...".
If anyone could spot what I'm doing wrong it would be much appreciated!
TIA,
Ed Metcalfe.
Please do not feed the trolls.....
I want to use the code below to read the relationships in one database and recreate them in another database.
Everything appears to be fine until it reaches the ThisDB.Relations.Append NewRel line, at which point I get an error message "You do not have the necessary permissions to use the '<tablename>' object...".
If anyone could spot what I'm doing wrong it would be much appreciated!
Code:
Public Sub TransferAllRelationships(ByVal strDB_Path As String)
Dim OtherDB As DAO.Database
Dim ExtRel As DAO.Relation
Dim ThisDB As DAO.Database
Dim NewRel As DAO.Relation
Dim pntr As Integer
Dim MyField As DAO.Field
Set OtherDB = OpenDatabase(strDB_Path, , True)
Set ThisDB = CurrentDb()
For Each ExtRel In OtherDB.Relations
Set NewRel = ThisDB.CreateRelation(ExtRel.Name, ExtRel.Table, ExtRel.ForeignTable, ExtRel.Attributes)
For pntr = 0 To ExtRel.Fields.Count - 1
NewRel.Fields.Append NewRel.CreateField(ExtRel.Fields(pntr).Name)
NewRel.Fields(pntr).ForeignName = ExtRel.Fields(pntr).ForeignName
Next pntr
ThisDB.Relations.Append NewRel 'Fails here - insufficient permissions on table?!
Next ExtRel
End Sub
TIA,
Ed Metcalfe.
Please do not feed the trolls.....