VCS_Reference.bas 3.5 KB

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