bushwacka666
New member
- Local time
- Today, 03:43
- Joined
- Jan 29, 2025
- Messages
- 12
Hello again all,
We have a form with a text box called txtEditHaul (format is Fixed) and when a user types a figure in this field it needs to update a couple of Currency fields in a table. This is the original VBA code in the After Update of the box:
Seems straightforward enough and, indeed, when this is run on a computer set to UK region, it works flawlessly. The catch is that a user needs to have their computer’s region set to Italy - in this case any entered figure with a decimal then causes the code to fail with a syntax error on the very first line.
Now I know that the crux of the issue seems to be that the Italians reverse their commas and decimal points, so for example 1,000.50 in the UK would be written as 1.000,50 in Italy. I’ve been testing with the figure 4.25/4,25 (i.e. no 1000 separator) so the problem seems to be the comma as a decimal. I could easily enter 4,25 directly into the table fields without issue so I know it’ll accept the figure, but the Update query doesn’t want to know.
From what I’ve been able to figure out thus far in trying to research the issue, the DoCmd.RunSQL command can’t really deal with these kind of scenarios. Finding a solution is very difficult but I did come across one suggestion which I have tried, using a string and Val function. The amended code is as follows:
The syntax error no longer occurs, however I now get a new error about having the wrong number of arguments. The debug again takes me to the first line (after the Dims):
This possibility wasn’t mentioned on the site where I found this solution, and I can’t see any other issues with the formatting of this code, so I presume the comma “decimal” is still tripping things up despite the Val formatting. The debug.print strsql line in the code results in
I've also tried the above using CDec instead of Val, but no joy there either.
Really struggling to find a solution that’s going to work here. If anybody could please provide any suggestions, I would sincerely appreciate it. Many thanks in advance.
We have a form with a text box called txtEditHaul (format is Fixed) and when a user types a figure in this field it needs to update a couple of Currency fields in a table. This is the original VBA code in the After Update of the box:
Code:
DoCmd.RunSQL ("UPDATE [Order Details] SET ODHaulageRate = " & Me.txtEditHaul & " Where [ODMN] = " & Me.ODMN)
If Me.chkUsePallet = True Then
DoCmd.RunSQL ("UPDATE [Order Details] SET ODJobRate = " & Me.txtEditHaul * Me.ODPallets & " Where [ODMN] = " & Me.ODMN)
Else
DoCmd.RunSQL ("UPDATE [Order Details] SET ODJobRate = " & Me.txtEditHaul * Me.ODQty & " Where [ODMN] = " & Me.ODMN)
End If
Seems straightforward enough and, indeed, when this is run on a computer set to UK region, it works flawlessly. The catch is that a user needs to have their computer’s region set to Italy - in this case any entered figure with a decimal then causes the code to fail with a syntax error on the very first line.
Now I know that the crux of the issue seems to be that the Italians reverse their commas and decimal points, so for example 1,000.50 in the UK would be written as 1.000,50 in Italy. I’ve been testing with the figure 4.25/4,25 (i.e. no 1000 separator) so the problem seems to be the comma as a decimal. I could easily enter 4,25 directly into the table fields without issue so I know it’ll accept the figure, but the Update query doesn’t want to know.
From what I’ve been able to figure out thus far in trying to research the issue, the DoCmd.RunSQL command can’t really deal with these kind of scenarios. Finding a solution is very difficult but I did come across one suggestion which I have tried, using a string and Val function. The amended code is as follows:
Code:
Dim strSql as string
Dim strSql2 as string
strSql = ("UPDATE [Order Details] SET ODHaulageRate = Val(" & Me.txtEditHaul & ") Where [ODMN] = " & Me.ODMN)
If Me.chkUsePallet = True Then
strSql2 = ("UPDATE [Order Details] SET ODJobRate = Val(" & Me.txtEditHaul * Me.ODPallets & ") Where [ODMN] = " & Me.ODMN)
Else
strSql2 = ("UPDATE [Order Details] SET ODJobRate = Val(" & Me.txtEditHaul * Me.ODQty & ") Where [ODMN] = " & Me.ODMN)
End If
' check your sql and post if does not work
debug.print strsql
currentDb.execute strSql
currentDb.execute strSql2
The syntax error no longer occurs, however I now get a new error about having the wrong number of arguments. The debug again takes me to the first line (after the Dims):
This possibility wasn’t mentioned on the site where I found this solution, and I can’t see any other issues with the formatting of this code, so I presume the comma “decimal” is still tripping things up despite the Val formatting. The debug.print strsql line in the code results in
UPDATE [Order Details] SET ODHaulageRate = Val(4,25) Where [ODMN] = 1394063248
I've also tried the above using CDec instead of Val, but no joy there either.
Really struggling to find a solution that’s going to work here. If anybody could please provide any suggestions, I would sincerely appreciate it. Many thanks in advance.