InFlight
User
- Local time
- Tomorrow, 07:18
- Joined
- Jun 11, 2015
- Messages
- 130
Hi
i am using the following code to create a relationship. But it creates a one to many, and i need a one to one
i am using the following code to create a relationship. But it creates a one to many, and i need a one to one
Code:
Public Function CreateRelation(primaryTableName As String, primaryFieldName As String, foreignTableName As String, foreignFieldName As String, RelationshipName As String) As Boolean
On Error GoTo ErrHandler
Dim Dbs As DAO.Database
Dim newRelation As DAO.Relation
Dim relatingField As DAO.Field
Dim relationUniqueName As String
relationUniqueName = RelationshipName
Set Dbs = OpenDatabase(strMainData)
'Arguments for CreateRelation(): any unique name,
'primary table, related table, attributes.
Set newRelation = Dbs.CreateRelation(relationUniqueName, _
primaryTableName, foreignTableName)
'The field from the primary table.
Set relatingField = newRelation.CreateField(primaryFieldName)
'Matching field from the related table.
relatingField.ForeignName = foreignFieldName
'Add the field to the relation's Fields collection.
newRelation.Fields.Append relatingField
'Add the relation to the database.
Dbs.Relations.Append newRelation
Dbs.Close
Set Dbs = Nothing
CreateRelation = True
Exit Function
ErrHandler:
MsgBox Err.Description + " (" + relationUniqueName + ")"
CreateRelation = False
End Function