| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- Option Compare Database
- Option Private Module
- Option Explicit
- ' 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
-
- 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
- Else
- refName = Trim$(item(0))
- Application.References.AddFromFile refName
- End If
- go_on:
- Loop
- On Error GoTo 0
- InFile.Close
- Set InFile = Nothing
- Set fso = Nothing
- 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
- MsgBox "Failed to register " & GUID, , "Error: " & err.number
- 'Do we really want to carry on the import with missing references??? - Surely this is fatal
- 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
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set OutFile = fso.CreateTextFile(obj_path & "references.csv", overwrite:=True, Unicode:=False)
- For Each ref In Application.References
- 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
- End If
- Else
- line = ref.FullPath
- OutFile.WriteLine line
- End If
- Next
- OutFile.Close
- End Sub
|