yapılanlar
1 - ilişkileri kaydetmek için yeni bir tablo eklendi
2 - yeniden ilişkilendirmek için yazılan fonksiyonlar için modül eklendi
3 - referanslara ActiveX Data Object Library eklendi
sorunsuz çalışırsa tablo yerine ilişkiler diziye aktarılıp oradan da alınabilir
modüle eklenen kodlar
1 - ilişkileri alma ve kaydetme
Sub CbIliskiAl() 'ilişkileri alma ve kaydetme
CurrentDb.Execute " delete from TblIliski "
For Each rel In CurrentDb.Relations
With rel
If Left(.Name, 4) <> "MSys" Then
IliskiAd = .Name
IliskiOzellik = .Attributes
IliskiAnaTbl = .Table
IliskiForeignTbl = .ForeignTable
For Each fld In .Fields
IliskiAlan = fld.Name
IliskiForeignAlan = fld.ForeignName
CurrentDb.Execute " INSERT INTO TblIliski " _
& "(IliskiAd, AnaTabloAd, HedefTabloAd,AnaAlanAd,HedefALanAd,AlanAtrib) VALUES " _
& "('" & IliskiAd & "', '" & IliskiAnaTbl & "', '" & IliskiForeignTbl & "', '" & IliskiAlan & "', '" & IliskiForeignAlan & "'," & IliskiOzellik & ");"
Next
End If
End With
Next
End Sub
2 - İlişkileri Silme
Sub CbIliskiSil() 'İlişkileri Silme
For Each rel In CurrentDb.Relations
If Left(rel.Name, 4) <> "MSys" Then CurrentDb.Relations.Delete (rel.Name)
Next rel
End Sub
3 - İlişkileri yeniden oluşturma
Sub CBIliskiKur()
Dim Sql As String
Dim ADO_RS As ADODB.Recordset
Set ADO_RS = New ADODB.Recordset
SQL = "select * from [TblIliski]"
ADO_RS.Open SQL, CurrentProject.Connection, 3, 1
Set db = CurrentDb
With ADO_RS
Do Until .EOF
Set newRelation = db.CreateRelation(.Fields(0), .Fields(1), .Fields(2))
Set relatingField = newRelation.CreateField(.Fields(3)) 'The field from the primary table.
relatingField.ForeignName = .Fields(4) 'Matching field from the related table.
newRelation.Fields.Append relatingField 'Add the field to the relation's Fields collection.
newRelation.Attributes = .Fields(5)
db.Relations.Append newRelation
.MoveNext
Loop
End With
ADO_RS.Close
Set ADO_RS = Nothing 'Attributes
Set db = Nothing ' CreateRelation = True
End Sub