| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- Option Compare Database
- Option Private Module
- Option Explicit
- Dim ignoreref As String ' for tests
- Public Sub set_ignoreref(str)
- ignoreref = str
- End Sub
- ' Import References from a CSV, true=SUCCESS
- Public Function ImportReferences(ByVal obj_path As String) As Boolean
- Dim FSO As Object
- Dim InFile As Object
- Dim Line As String
- Dim item() As String
- Dim GUID As String
- Dim Major As Long
- Dim Minor As Long
- Dim filename As String
- Dim refName As String
- Dim count As Integer
- count = 0
- filename = dir$(obj_path & "references.csv")
- If Len(filename) = 0 Then
- ImportReferences = False
- Exit Function
- End If
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set InFile = FSO.OpenTextFile(obj_path & filename, iomode:=ForReading, Create:=False, Format:=TristateFalse)
-
- On Error GoTo failed_guid
- Do Until InFile.AtEndOfStream
- Line = InFile.readline
- item = Split(Line, ",")
-
- If UBound(item) = 2 Then 'a ref with a guid
- GUID = Trim$(item(0))
- Major = CLng(item(1))
- Minor = CLng(item(2))
- Application.References.AddFromGuid GUID, Major, Minor
- count = count + 1
- Else
- refName = Trim$(item(0))
- Application.References.AddFromFile refName
- count = count + 1
- End If
- go_on:
- Loop
- On Error GoTo 0
- InFile.Close
- Set InFile = Nothing
- Set FSO = Nothing
- logger "ImportReferences", "INFO", count & " imported from " & filename
- ImportReferences = True
- Exit Function
-
- failed_guid:
- If err.Number = 32813 Then
- 'The reference is already present in the access project - so we can ignore the error
- Resume Next
- Else
- logger "ImportReferences", "ERROR", "Failed to register " & GUID
- Resume go_on
- End If
-
- End Function
- ' Export References to a CSV
- Public Sub ExportReferences(ByVal obj_path As String)
- Dim FSO As Object
- Dim OutFile As Object
- Dim Line As String
- Dim ref As Reference
- Dim count As Integer
- Dim item As Variant
- count = 0
-
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set OutFile = FSO.CreateTextFile(obj_path & "references.csv", overwrite:=True, unicode:=False)
- For Each ref In Application.References
-
- For Each item In Split(ignoreref, ",")
- If ref.name = CStr(item) Then GoTo go_on
- Next item
-
- If ref.GUID <> vbNullString Then ' references of types mdb,accdb,mde etc don't have a GUID
- If Not ref.BuiltIn Then
- Line = ref.GUID & "," & CStr(ref.Major) & "," & CStr(ref.Minor)
- OutFile.WriteLine Line
- logger "ExportReferences", "DEBUG", "> Reference " & Line & " exported"
- count = count + 1
- End If
- Else
- Line = ref.FullPath
- OutFile.WriteLine Line
- logger "ExportReferences", "DEBUG", "> Reference " & Line & " exported"
- count = count + 1
- End If
- go_on:
- Next
- OutFile.Close
-
- logger "ExportReferences", "INFO", count & " references exported to" & obj_path & "references.csv"
- End Sub
|