Access 2013 form field value gets cut off on chang

2019-09-09 14:45发布

问题:

Recently I created a form which loads some records from an SQL (linked) database.

I want to display some field values (which are decimal numbers - 30,2 in the sql server).

The values are loaded in the form and displayed with a comma for the decimals and a point as a 1000 separator like this: 5.222,55. (Language settings on the computer).

Though the thing is, when I change the 5 before the point into any number then the value gets truncated and it sees the point as the decimal separator. So for example, if I only select the number 5 on the 5.222,55 number (so I leave the point) and then change it to a 2, the value is changed to 2,22.

Though when I select the whole number or the first number AND the point then it changes correctly. So how can I get this right? The easy way is to just select the whole number on changing but I just want it to work in every way. Perhaps I can achieve it with VBA? I tried setting the format option (back in access 2000 I believe I could set the text field to long integer or currency or something but I cant find this in the access 2013 field properties).

Additional information:

  • I am linking with a SQL server 2012,
  • The linked table in Access sees the fields record source (the SQL fields) as short text (while they are decimals in the SQL server)

回答1:

Access cannot handle a 30,2 decimal, thus it is converted to text by teh ODBC driver.

So, either convert back and forth between text and numerics with Str and Val (the C* functions won't do), or change the data type of the field in SQL Server to, say, Money (= Currency in Access).