Option Compare Database Option Private Module Option Explicit Public Function utf8_conversion() As Boolean ' utf8 conversion is needed for Access 2007 and later utf8_conversion = (CurrentProject.FileFormat >= acFileFormatAccess2007) End Function Public Function get_container_name(ByVal acType As Integer) 'return the name of an access object container from its acType Select Case acType Case acTable get_container_name = "tables" Case acForm get_container_name = "forms" Case acReport get_container_name = "reports" Case acMacro get_container_name = "scripts" Case acModule get_container_name = "modules" End Select End Function ' Export a database object with optional UCS2-to-UTF-8 conversion. Public Sub ExportDocument(ByVal acType As Integer, ByVal obj_name As String, ByVal file_path As String) On Error GoTo err ' encoding can be either 'UCS2' (default), either 'utf-8' logger "ExportDocument", "DEBUG", "Try to export " & obj_name & "(type " & acType & ") from: " & file_path mktree parent_dir(file_path) del_if_exist file_path Application.SaveAsText acType, obj_name, file_path If acType <> acModule Then If utf8_conversion() Then logger "ExportDocument", "DEBUG", "Encode file in UTF-8" Dim tempFileName As String tempFileName = TempFile() ConvertUcs2Utf8 file_path, tempFileName Kill file_path Name tempFileName As file_path End If SanitizeFile file_path End If logger "ExportDocument", "DEBUG", "> exported" Exit Sub err: logger "ExportDocument", "CRITICAL", "Unable to export " & obj_name & " [" & err.Description & "]" End Sub ' Import a database object with optional UTF-8-to-UCS2 conversion. Public Sub ImportDocument(ByVal acType As Integer, ByVal obj_name As String, ByVal file_path As String) On Error GoTo err Dim tempFileName As String logger "ImportDocument", "DEBUG", "Try to import " & obj_name & "(type " & acType & ") from: " & file_path If acType <> acModule Then If utf8_conversion() Then logger "ImportDocument", "DEBUG", "Encode in UCS2 before import" tempFileName = TempFile() ConvertUtf8Ucs2 file_path, tempFileName file_path = tempFileName End If End If Application.LoadFromText acType, obj_name, file_path logger "ImportDocument", "DEBUG", "> imported" end_: If Len(tempFileName) > 0 Then del_if_exist tempFileName End If Exit Sub err: logger "ImportDocument", "CRITICAL", "Unable to import " & obj_name & " [" & err.Description & "]" End Sub