• VBA to check referential integrity?

    Author
    Topic
    #354937

    How would I check referential integrity using VBA?

    I have a massive number of tables and relationships in this database and need to check that referential integrity is turned on for each relationship.

    Checking this stuff manually in the relationship window would be a nightmare.

    Thanks in advance.

    Viewing 0 reply threads
    Author
    Replies
    • #522588

      Hi Stephan,

      Try this code:

      Function PrintRelationships()
          Dim dbs As DAO.Database
          Dim rln As DAO.Relation
              
          Set dbs = CurrentDb()
          For Each rln In dbs.Relations
              Debug.Print "Name: " & rln.Name & vbCrLf _
              & "Table: " & rln.Table & vbCrLf _
              & "Foreign Table: " & rln.ForeignTable & vbCrLf _
              & "Attributes: " & rln.Attributes & vbCrLf
          Next 'rln
      End Function

      You’ll have to look in the object browser (DAO.RelationAttributeEnum) for the definitions of the Long codes. You can also consult the Access helpfile under Relationship Attributes.

      HTH thumbup

    Viewing 0 reply threads
    Reply To: VBA to check referential integrity?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: