Nobody can answer! Problem with commas and dots
Hi Poppe
I always thought the Format string worked independently of the locale -
every day is a learning day :-)
Try the following:
Dim strPointNum As String, strCommaNum As String, p As Integer
Dim strSQL As String
strcommaNum = Format(ActiveSheet.Cells(8, 5), "0.00")
p = InStr(1, strCommaNum, ",", vbTextCompare)
strPointNum = Left(strCommaNum, p - 1) & "." & Right(strCommaNum, 2)
strSQL = "INSERT INTO company (salary) SELECT " & strPointNum & ";"
This assumes the formatted number has two decimal places. If you need a
different number, you must adjust the code accordingly.
I tried this going from my number format (UK) to yours (Finland) and it
worked - substituting my "." with your ",". I have swapped the comma and
decimal stres around, so it should work as-is for you.
Nick
--
Nick
"Poppe" wrote:
Thanks for your replies. I tried all of above, but nothing works.
Results:
------------------
Per Jessen: Your code works only with values with a single comma. If i have
larger values like 100,400.60 - it does not. That would result in wrong
values
------------------
Peter T:
Application.International(xlDecimalSeparator) = The output result is ","
If i force the separator as dot, the execute command will still send the
value with comma:
With Application
.DecimalSeparator = "."
.UseSystemSeparators = False
End With
"INSERT INTO company (salary) SELECT " & ActiveSheet.Cells(8, 5))
Result = "INSERT INTO company (salary) SELECT 1400,50"
------------------
NickH:
"INSERT INTO company (salary) SELECT " & Format(ActiveSheet.Cells(8,
5),"0.00")
Result = "INSERT INTO company (salary) SELECT 1400,50"
It still uses commas.
------------------
It's really a tough problem. I also think it should read them in "raw" mode
where there is no comma, but for some reason it does. My regional setting in
control panel is Finnish.
What to do? This really seems like a question with no answer..
|