| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- Option Compare Database
- Option Private Module
- Option Explicit
- 'Dim UTF8CONVERSION As Boolean
- 'Public Sub activate_Utf8Conversion()
- ' UTF8CONVERSION = True
- 'End Sub
- Const UTF8CONVERSION = True
- 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 UTF8CONVERSION 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 UTF8CONVERSION 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
|