| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- Option Compare Database
- Option Private Module
- Option Explicit
- Public Sub ExportRelation(ByVal rel As DAO.Relation, ByVal filepath As String)
- Dim fso As Object
- Dim OutFile As Object
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set OutFile = fso.CreateTextFile(filepath, overwrite:=True, unicode:=False)
-
- OutFile.WriteLine rel.Attributes 'RelationAttributeEnum
- OutFile.WriteLine rel.name
- OutFile.WriteLine rel.table
- OutFile.WriteLine rel.foreignTable
-
- Dim f As DAO.Field
- For Each f In rel.Fields
- OutFile.WriteLine "Field = Begin"
- OutFile.WriteLine f.name
- OutFile.WriteLine f.ForeignName
- OutFile.WriteLine "End"
- Next
-
- OutFile.Close
- logger "ExportRelation", "DEBUG", "Relation " & rel.name & " exported to " & filepath
- End Sub
- Public Sub ImportRelation(ByVal filepath As String)
- Dim fso As Object
- Dim InFile As Object
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set InFile = fso.OpenTextFile(filepath, iomode:=ForReading, create:=False, Format:=TristateFalse)
- Dim rel As DAO.Relation
- Set rel = New DAO.Relation
-
- rel.Attributes = InFile.readline
- rel.name = InFile.readline
- rel.table = InFile.readline
- rel.foreignTable = InFile.readline
-
- Dim f As DAO.Field
- Do Until InFile.AtEndOfStream
- If "Field = Begin" = InFile.readline Then
- Set f = New DAO.Field
- f.name = InFile.readline
- f.ForeignName = InFile.readline
- If "End" <> InFile.readline Then
- Set f = Nothing
- err.Raise 40000, "ImportRelation", "Missing 'End' for a 'Begin' in " & filepath
- End If
- rel.Fields.Append f
- End If
- Loop
-
- InFile.Close
-
- CurrentDb.Relations.Append rel
- logger "ImportRelation", "DEBUG", "Relation " & rel.name & " imported from " & filepath
- End Sub
|