Question : How do I create a relationship in access and specify that referential integrity should NOT be enforced?

I have some tables that I import from quickbooks every week into access.  They are too big to link so I just created a macro to import them.  After importing I want to recreate the relationships automatically.  Upon doing this I get the following error.

Run-time error '3201' You cannot add or change a record because a related record is required in table 'ProjectsFinancialRelatonshipKey'

When I try to create the relationship manually in access it won't let me because of referential integrity(some records exist in the many table that do not exist in the primary table).  If I do not check enforce referencial integrity it creates the relationship.  The following code exhibits where the error occurs.  I have tried running the code with and without the line:
Rel.Attributes = dbRelationUpdateCascade And dbRelationDeleteCascade
included.  Same error either way.  Any advice?

Thanks, Eric
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Sub CreateRelationship(RelName As String, Table1 As String, Table2 As String, PrimField As String, ForField As String)
Dim db As DAO.Database
Dim Rel As DAO.Relation
Dim Fld As Field
Set db = CurrentDb()
Set Rel = db.CreateRelation(RelName, Table1, Table2)
Rel.Attributes = dbRelationUpdateCascade And dbRelationDeleteCascade
Set Fld = Rel.CreateField(PrimField)
Fld.ForeignName = ForField
Rel.Fields.Append Fld 'This is the line causing the error
db.Relations.Append Rel
db.Relations.Refresh
Set db = Nothing
End Sub

Answer : How do I create a relationship in access and specify that referential integrity should NOT be enforced?

Okay sagacity thanks for the help.

dbRelationLeft doesn't turn off referential integrity but makes the relationship a type 2 Join: "Include ALL records from 'Customer' and only those records from 'ProjectsFinancialRelationshipKey' where the joined fields are equal."  Now, i'm new to databases so this in conjunction with cascading might be the same thing, however I just figured out however how to make the relation without enforcing referential integrity(at least how to explicitly uncheck the box).  In the Rel.Attributes line you add dbRelationDontEnforce
i.e.
Rel.Attributes = dbRelationDontEnforce

Anyway Thanks,
Eric
Random Solutions  
 
programming4us programming4us