问题
I have an application that ships to the customer with a JET database including a relationship diagram which more savvy users are invited to view to gain insight into the construction of the database.
I also have code in my application to update the database structure when new versions require new tables, new columns, or modified queries. I do this by pushing SQL through the ADO connection it works fine.
The problem is that if I add a new table with a constraint that relates it to an existing table (for instance, I add EmployeeHobbies with an FK relationship to an existing PK in Employees), while the table is constructed correctly the new relationship does not appear in the relationship diagram. Over time the diagram becomes progressively less complete.
Is there a programmatic method to force Access to update its relationship diagram from constraint information in the database or, failing that, is the relationship diagram stored in some hidden system object that I can update directly to reflect my changes?
Edit: I failed to make clear that my application is written in Delphi, not MS Access. Users who have a copy of MS Access can see the relationship diagram, others cannot.
回答1:
I do not know if RunCommand will suit, but for what it's worth:
DoCmd.RunCommand acCmdRelationships
DoCmd.RunCommand acCmdShowAllRelationships
回答2:
You may be able to leverage Stephen Lebans' SaveRelationshipView for this. His code saves properties for each item from the Relationships view to a table. Later the same layout view can be recreated from the table.
You could adjust your copy of the Relationships view to determine the values to include for a new row in the tblRelationshipViews table. Then let the users recreate their Relationships view based on the updated table information. Perhaps you could even automate to do it for them automatically.
来源:https://stackoverflow.com/questions/4136464/adding-to-ms-access-relationship-diagram-programmatically