K
komis
Guest
Hi all,
I have a problem trying to replicate relations from an external database into a new file.
I have the following code, which doesn't work because it says the relation I am trying to append to the current db has no fields. If I use the .append method to append the taField object to the taRel collection, it says invalid operation, error 3219... helpppppp..... btw taRel=target relationship (to be created) and imRel=imported relationship (resides in external mdb).
Private Sub createRels()
Dim imRel As DAO.Relation
Dim taRel As DAO.Relation
Dim strpath As String
Dim imdb As DAO.Database
Dim imField As DAO.Field
Dim taField As DAO.Field
Dim x As Integer
Dim i As Integer
'get the external mdb path
Text24.SetFocus
strpath = Text24.text & "\" & List22.Value
Set imdb = DBEngine.Workspaces(0).OpenDatabase(strpath)
For i = 0 To imdb.Relations.count - 1
Set imRel = imdb.Relations(i)
Set taRel = CurrentDb.CreateRelation(imRel.name, imRel.Table, imRel.ForeignTable, imRel.Attributes)
For x = 0 To imRel.Fields.count - 1
MsgBox "field " & x & " in imrel"
Set imField = imRel.Fields(x)
Set taField = taRel.CreateField(imField.name)
MsgBox "fields now in tarel " & taRel.Fields.count
taField.ForeignName = imField.ForeignName
'if I include the following line, it says invalid operation, if I don't it says cant append a relationship without fields... grrrrrrrr....
'taRel.Fields.Append (taField)
Next x
CurrentDb.Relations.Append taRel
Next i
CurrentDb.Relations.Refresh
End Sub
I have a problem trying to replicate relations from an external database into a new file.
I have the following code, which doesn't work because it says the relation I am trying to append to the current db has no fields. If I use the .append method to append the taField object to the taRel collection, it says invalid operation, error 3219... helpppppp..... btw taRel=target relationship (to be created) and imRel=imported relationship (resides in external mdb).
Private Sub createRels()
Dim imRel As DAO.Relation
Dim taRel As DAO.Relation
Dim strpath As String
Dim imdb As DAO.Database
Dim imField As DAO.Field
Dim taField As DAO.Field
Dim x As Integer
Dim i As Integer
'get the external mdb path
Text24.SetFocus
strpath = Text24.text & "\" & List22.Value
Set imdb = DBEngine.Workspaces(0).OpenDatabase(strpath)
For i = 0 To imdb.Relations.count - 1
Set imRel = imdb.Relations(i)
Set taRel = CurrentDb.CreateRelation(imRel.name, imRel.Table, imRel.ForeignTable, imRel.Attributes)
For x = 0 To imRel.Fields.count - 1
MsgBox "field " & x & " in imrel"
Set imField = imRel.Fields(x)
Set taField = taRel.CreateField(imField.name)
MsgBox "fields now in tarel " & taRel.Fields.count
taField.ForeignName = imField.ForeignName
'if I include the following line, it says invalid operation, if I don't it says cant append a relationship without fields... grrrrrrrr....
'taRel.Fields.Append (taField)
Next x
CurrentDb.Relations.Append taRel
Next i
CurrentDb.Relations.Refresh
End Sub