简体   繁体   中英

VBA Project, change of a decimal separator in a variable value

I'm trying to upload a value directly from VBA to SQL via ADO - I collect values into a Dim srtSql As String and then insert them into the SQL table. The issue relates to a "Currency" value with a comma delimiter. I have a comma decimal separator and the value of my variable looks like (94,5), but a dot (94.5) is needed. The code below doesn't solves the problem.

With Application.
    .DecimalSeparator = "."
    .UseSystemSeparators = False
End With

While searching for a solution I've got a code below from the case How to ensure dot as decimal separator when exporting excel to csv? to check the separator.

Dim myShell, regDecSep    
Set myShell = CreateObject("WScript.Shell")
regDecSep = myShell.RegRead("HKCU\Control Panel\International\sDecimal")

Debug.Print "System decimal separator: " & regDecSep

I'm not familiar with Registry. My question - is it any way to set a system decimal separator via RegWrite or any other method? PS I would like to avoid a vba Replace() solution.

Your code is about Excel, not SQL. So, convert decimal values to string expressions for these having a dot as the decimal separator. Str will do that:

strSql = "Insert Into Table1 (SomeTextField, Amount, AnotherTextField) " & _
    "Values ('" & Text1 & "', Str(" & YourAmount & "), '" Text2 & "')"

Also, see my function CSql for concatenating SQL expressions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM