I didnt see anything on creating an Access Relationship when
I searched, so here is my code to create a relationship.

It also creates a new blank Access database, Add 2 new tables,
creates new fields, set primary keys, and then its creates a
relationship between the two tables based on the primary keys.

Works on Access versions 2000 +.
I don't have Access 97 anymore so un-tested on 97.

VB Code:
  1. Option Explicit
  2. 'Add reference to MS Access xx.0 Object Library
  3. 'Add reference to DAO 3.x Object Library
  4. Private oApp As Access.Application
  5.  
  6. Private Sub Form_Load()
  7.    
  8.     Dim oRel As DAO.Relation
  9.     Dim oDB As DAO.Database
  10.     Dim oTable1 As DAO.TableDef
  11.     Dim oTable2 As DAO.TableDef
  12.     Dim oIndex As DAO.Index
  13.    
  14.     'Create new blank access database
  15.     Set oApp = New Access.Application
  16.     oApp.NewCurrentDatabase App.Path & "\MyDB2.mdb"
  17.     Set oDB = oApp.CurrentDb
  18.     oApp.Visible = True
  19.    
  20.     'Create first table (Table1)
  21.     Set oTable1 = oDB.CreateTableDef("Table1")
  22.     With oTable1
  23.         .Fields.Append .CreateField("Field1", dbInteger)
  24.         .Fields.Append .CreateField("Field2", dbText)
  25.         .Fields.Append .CreateField("Field3", dbText)
  26.         .Fields.Append .CreateField("Field4", dbText)
  27.     End With
  28.     oDB.TableDefs.Append oTable1
  29.    
  30.     'Create an index on Table1
  31.     Set oIndex = oTable1.CreateIndex
  32.     With oIndex
  33.         .Name = "Field1Index"
  34.         .Fields.Append .CreateField("Field1")
  35.         .Primary = True
  36.     End With
  37.     oTable1.Indexes.Append oIndex
  38.    
  39.     'Create second table (Table2)
  40.     Set oTable2 = oDB.CreateTableDef("Table2")
  41.     With oTable2
  42.         .Fields.Append .CreateField("Field1", dbInteger)
  43.         .Fields.Append .CreateField("Field2", dbText)
  44.         .Fields.Append .CreateField("Field3", dbText)
  45.         .Fields.Append .CreateField("Field4", dbText)
  46.     End With
  47.     oDB.TableDefs.Append oTable2
  48.    
  49.     'Create an index on Table2
  50.     Set oIndex = Nothing
  51.     Set oIndex = oTable2.CreateIndex
  52.     With oIndex
  53.         .Name = "Field1Index"
  54.         .Fields.Append .CreateField("Field1")
  55.         .Primary = True
  56.     End With
  57.     oTable2.Indexes.Append oIndex
  58.    
  59.     'Create relationship between table1 and table2
  60.     Set oRel = oApp.CurrentDb.CreateRelation("MyRelationship", "Table1", "Table2", dbRelationLeft Or dbRelationUpdateCascade Or dbRelationDeleteCascade)
  61.     oRel.Fields.Append oRel.CreateField("Field1")
  62.     oRel.Fields("Field1").ForeignName = "Field1"
  63.     oApp.CurrentDb.Relations.Append oRel
  64.  
  65.     MsgBox "Done!"
  66.     Unload Me
  67.    
  68. End Sub