| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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)
- ' 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", obj_name & " (type " & acType & ") exported to " & file_path
- 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
|