VCS_Reference.bas 2.9 KB

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