VCS_Reference.bas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. Option Compare Database
  2. Option Private Module
  3. Option Explicit
  4. Dim ignoreref As String ' for tests
  5. Public Sub set_ignoreref(str)
  6. ignoreref = str
  7. End Sub
  8. ' Import References from a CSV, true=SUCCESS
  9. Public Function ImportReferences(ByVal obj_path As String) As Boolean
  10. Dim FSO As Object
  11. Dim InFile As Object
  12. Dim Line As String
  13. Dim item() As String
  14. Dim GUID As String
  15. Dim Major As Long
  16. Dim Minor As Long
  17. Dim filename As String
  18. Dim refName As String
  19. Dim count As Integer
  20. count = 0
  21. filename = dir$(obj_path & "references.csv")
  22. If Len(filename) = 0 Then
  23. ImportReferences = False
  24. Exit Function
  25. End If
  26. Set FSO = CreateObject("Scripting.FileSystemObject")
  27. Set InFile = FSO.OpenTextFile(obj_path & filename, iomode:=ForReading, Create:=False, Format:=TristateFalse)
  28. On Error GoTo failed_guid
  29. Do Until InFile.AtEndOfStream
  30. Line = InFile.readline
  31. item = Split(Line, ",")
  32. If UBound(item) = 2 Then 'a ref with a guid
  33. GUID = Trim$(item(0))
  34. Major = CLng(item(1))
  35. Minor = CLng(item(2))
  36. Application.References.AddFromGuid GUID, Major, Minor
  37. count = count + 1
  38. Else
  39. refName = Trim$(item(0))
  40. Application.References.AddFromFile refName
  41. count = count + 1
  42. End If
  43. go_on:
  44. Loop
  45. On Error GoTo 0
  46. InFile.Close
  47. Set InFile = Nothing
  48. Set FSO = Nothing
  49. logger "ImportReferences", "INFO", count & " imported from " & filename
  50. ImportReferences = True
  51. Exit Function
  52. failed_guid:
  53. If err.Number = 32813 Then
  54. 'The reference is already present in the access project - so we can ignore the error
  55. Resume Next
  56. Else
  57. logger "ImportReferences", "ERROR", "Failed to register " & GUID
  58. Resume go_on
  59. End If
  60. End Function
  61. ' Export References to a CSV
  62. Public Sub ExportReferences(ByVal obj_path As String)
  63. Dim FSO As Object
  64. Dim OutFile As Object
  65. Dim Line As String
  66. Dim ref As Reference
  67. Dim count As Integer
  68. Dim item As Variant
  69. count = 0
  70. Set FSO = CreateObject("Scripting.FileSystemObject")
  71. Set OutFile = FSO.CreateTextFile(obj_path & "references.csv", overwrite:=True, unicode:=False)
  72. For Each ref In Application.References
  73. For Each item In Split(ignoreref, ",")
  74. If ref.name = CStr(item) Then GoTo go_on
  75. Next item
  76. If ref.GUID <> vbNullString Then ' references of types mdb,accdb,mde etc don't have a GUID
  77. If Not ref.BuiltIn Then
  78. Line = ref.GUID & "," & CStr(ref.Major) & "," & CStr(ref.Minor)
  79. OutFile.WriteLine Line
  80. logger "ExportReferences", "DEBUG", "> Reference " & Line & " exported"
  81. count = count + 1
  82. End If
  83. Else
  84. Line = ref.FullPath
  85. OutFile.WriteLine Line
  86. logger "ExportReferences", "DEBUG", "> Reference " & Line & " exported"
  87. count = count + 1
  88. End If
  89. go_on:
  90. Next
  91. OutFile.Close
  92. logger "ExportReferences", "INFO", count & " references exported to" & obj_path & "references.csv"
  93. End Sub