VB导出访问Mysql失败的货币格式

时间:2015-07-09 09:18:14

标签: mysql vba odbc ms-access-2003

Access 2003上的以下VBA脚本将所有表和数据导出到MySQL。 除货币数据外,一切都有效,它们被转换为整数而不是浮点数。浮动正确导出。

在Access 2003中

price : 1,22 € (currency format)
VAT : 1,115 (float)

成为mysql:

price : 1
VAT : 1.115

这是脚本:

Option Compare Database

Private Sub Détail_Click()

End Sub

Private Sub export_mysql_Click()
    On Error GoTo Err_export_mysql_Click

        Dim sTblNm As String
        Dim sTypExprt As String
        Dim sCnxnStr As String, vStTime As Variant
        Dim db As Database, tbldef As DAO.TableDef

        On Error GoTo ExportTbls_Error

        sTypExprt = "ODBC"
        'sCnxnStr = "ODBC;DSN=DSNname;UID=userOnServer;PWD=pwdOnServer"
        sCnxnStr = "ODBC;DSN=exporteau;UID=exporteau;PWD=xxxxxxxxxxx" 'Create the connection string
        vStTime = Timer
        Application.Echo False, "Visual Basic code is executing."

        Set db = CurrentDb()

        For Each tbldef In db.TableDefs
        Debug.Print tbldef.Name
        sTblNm = tbldef.Name
        DoCmd.TransferDatabase acExport, sTypExprt, sCnxnStr, acTable, sTblNm, sTblNm
        Next tbldef

        MsgBox "Exportation terminée"
        On Error GoTo 0
SmoothExit_ExportTbls:
        Set db = Nothing
        Application.Echo True
        Exit Sub

ExportTbls_Error:
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExportTblsODST"
        Resume SmoothExit_ExportTbls

Exit_export_mysql_Click:
            Exit Sub

Err_export_mysql_Click:
            MsgBox Err.Description
            Resume Exit_export_mysql_Click

End Sub

Private Sub export_mysql_DblClick(Cancel As Integer)

End Sub

1 个答案:

答案 0 :(得分:0)

MS Access 2002使用货币的系统区域设置。

一旦设置为使用.而不是,分隔小数,我就得到了我的数字。