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? P.S. I would like to avoid a vba Replace() solution.
CodePudding user response:
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.