A family of Microsoft relational database management systems designed for ease of use.
Strange - the documentation states that the Name argument of CreateRelation is optional.
Try the following.
Sub DoARelation()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rel As DAO.Relation
Dim fld As DAO.Field
Dim i As Long
On Error Resume Next
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("TblAlterRelation", dbOpenForwardOnly)
Do While Not rst.EOF
'Create a new relation.
i = i + 1
Set rel = dbs.CreateRelation("Relation" & i)
'Define its properties.
With rel
'Specify the primary table.
.Table = rst!MainTableName
'Specify the related table.
.ForeignTable = rst!FTableName
'Specify attributes for cascading updates and deletes.
.Attributes = dbRelationUpdateCascade + dbRelationDeleteCascade
'Add the fields to the relation.
'Field name in primary table.
Set fld = .CreateField(rst!MainTablePKName)
'Field name in related table.
fld.ForeignName = rst!FTableChildName
'Append the field.
.Fields.Append fld
.Fields.Refresh
'Repeat for other fields if a multi-field relation.
End With
'Save the newly defined relation to the Relations collection.
dbs.Relations.Append rel
dbs.Relations.Refresh
rst.MoveNext
Loop
rst.Close
'Clean up
Set fld = Nothing
Set rel = Nothing
Set rst = Nothing
Set dbs = Nothing
End Sub