| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- Option Compare Database
- Option Private Module
- Option Explicit
- Public Sub ExportRelation(ByVal rel As DAO.Relation, ByVal filepath As String)
- On Error GoTo err
- Dim FSO As Object
- Dim OutFile As Object
-
- Dim relname As String
- relname = rel.name
-
- 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 " & relname & " exported to " & filepath
- Exit Sub
- err:
- logger "ImportRelation", "ERROR", "Unable to import relation " & relname & " [" & err.Description & "]"
- End Sub
- Public Sub ImportRelation(ByVal filepath As String)
- On Error GoTo err
- 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
- Dim relname As String
- relname = rel.name
- 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
- logger "ImportRelation", "ERROR", "Missing 'End' for a 'Begin' in " & filepath
- GoTo next_rel
- End If
- rel.Fields.Append f
- End If
- next_rel:
- Loop
-
- InFile.Close
-
- CurrentDb.Relations.Append rel
- logger "ImportRelation", "DEBUG", "Relation " & relname & " imported from " & filepath
- Exit Sub
- err:
- logger "ImportRelation", "ERROR", "Unable to import relation " & relname & " [" & err.Description & "]"
- End Sub
|