Hopefully someone out there can help. I am currently trying to write
some code to allow me to delete a table, then recreate it and
re-establish the relationships. I seem to have hit a snag in the
recreation of the relationships. Code is:
Sub Woof()
Dim dbs As Database
Dim fld As Field, rel1 As Relation, rel2 As Relation
Set dbs = CurrentDb
Set rel1 = dbs.CreateRelat ion("Emp No", "Upload", "FTE Table")
rel1.Attributes = dbRelationDelet eCascade +
dbRelationUpdat eCascade
Set fld = rel1.CreateFiel d("Emp No")
fld.ForeignName = "Emp No"
rel1.Fields.App end fld
dbs.Relations.A ppend rel1
MsgBox "Relation '" & rel1.Name & "' created."
Set dbs = Nothing
Set dbs = CurrentDb
Set rel2 = dbs.CreateRelat ion("Cost Centre", "Department ",
"FTE Table")
rel2.Attributes = dbRelationDelet eCascade +
dbRelationUpdat eCascade
Set fld = rel2.CreateFiel d("DepartmentCo stCentre")
fld.ForeignName = "Cost Centre"
rel2.Fields.App end fld
dbs.Relations.A ppend rel2
MsgBox "Relation '" & rel2.Name & "' created."
Set dbs = Nothing
End Sub
The code gets as far as dbs.Relations.A ppend rel1 and then errors out
with a message "Can't append a relation without fields defined". I
have tried a few different configurations of the field definition
section but i seem to be missing something. As this is the first time
I have tried this piece of code i'm not one hundred percent sure what
is causing the error.
Can anyone help?
Thanks
Jenni