My application uses Access to store the users data.
When starting a new file it copies a 'Master Database' .
Sometimes I update (add tables, fields, Queries or relationships) the Master and then need to update the application files. I have written a routine to do this - it checks the pplication DB against the master, and if it finds tables, fields, Queries or relationship missing copies them into the application files. this works well, except for the some Relationships. If my new master has a relationship that has referential integrity it does not copy - I get the error message "Index already exists"
What is worse it seems to create the Relationship partially so that even in Access the same message appears when trying to manually add the Relationship. And I cannot even find (in Access) the partially added relationship to delete it.
Can anyone see what I am doing wrong?
Thanks
Here is the code for the Relationships part
'refDB is the master
'newdb id the DB that needs updating
For Each RefRel In refDB.Relations
Set NewRel = Nothing
Set NewRel = newdb.Relations(RefRel.Name)
If NewRel Is Nothing Then'need to add the relationship to the new DB
msg = msg & "Add Relationship " & RefRel.Name & vbCrLf
'copy all relationship details from the master to the new db
Set NewRel = newdb.CreateRelation(RefRel.Name, RefRel.Table, RefRel.ForeignTable, RefRel.Attributes)
For Each refField In RefRel.Fields
Set newField = NewRel.CreateField
newField.Name = refField.Name
newField.ForeignName = refField.ForeignName
NewRel.Fields.Append newField
Next
Err = 0
newdb.Relations.Append NewRel
If Err > 0 Then
RelError = True
eMsg = eMsg & RefRel.Name & " " & RefRel.Table & "/" & RefRel.ForeignTable & " " & Err.Description & vbCrlf
End If
End If
Next
When starting a new file it copies a 'Master Database' .
Sometimes I update (add tables, fields, Queries or relationships) the Master and then need to update the application files. I have written a routine to do this - it checks the pplication DB against the master, and if it finds tables, fields, Queries or relationship missing copies them into the application files. this works well, except for the some Relationships. If my new master has a relationship that has referential integrity it does not copy - I get the error message "Index already exists"
What is worse it seems to create the Relationship partially so that even in Access the same message appears when trying to manually add the Relationship. And I cannot even find (in Access) the partially added relationship to delete it.
Can anyone see what I am doing wrong?
Thanks
Here is the code for the Relationships part
'refDB is the master
'newdb id the DB that needs updating
For Each RefRel In refDB.Relations
Set NewRel = Nothing
Set NewRel = newdb.Relations(RefRel.Name)
If NewRel Is Nothing Then'need to add the relationship to the new DB
msg = msg & "Add Relationship " & RefRel.Name & vbCrLf
'copy all relationship details from the master to the new db
Set NewRel = newdb.CreateRelation(RefRel.Name, RefRel.Table, RefRel.ForeignTable, RefRel.Attributes)
For Each refField In RefRel.Fields
Set newField = NewRel.CreateField
newField.Name = refField.Name
newField.ForeignName = refField.ForeignName
NewRel.Fields.Append newField
Next
Err = 0
newdb.Relations.Append NewRel
If Err > 0 Then
RelError = True
eMsg = eMsg & RefRel.Name & " " & RefRel.Table & "/" & RefRel.ForeignTable & " " & Err.Description & vbCrlf
End If
End If
Next