Display of numerical value with decimals in a text box

L

LarsM

In a table I have a numerical value defined as single precision. In a form I
have a text box, where I indicate the value, and where I can also change the
value, if I want. The value is always in the range > 0 and < 1. The text box
is 1.2 cm (about 0.47 ") wide. With "Font Name" = "Calibri" and "Font Size" =
11 this should give place for indicating the value wtih 4 decimals.

A correct decimal indication of a value stored with single precision can in
princpiple have an infinite number of decimals. In the field in the form with
limited width the value is basically shown as "############". When I go into
the field, as if I want to change the value, the value is shown with 7
decimals, so I have to use left and right arrows (or "home" and "end") to see
the value. If I use "home" once or "left arrow" several times, I see a zero
followed by a decimal point and the first 3 decimals. With right arrow I see
more decimals. As soon as I leave the field, the value is again shown as
"############". Basically I use "Decimal Places" = "Auto", but I also tried
"Decimal Places" = 3 or 2 or 1. This didn't do any difference. I also tried
to change some of the other "format" parameters of the text box without
result.

I wonder why MS Access in a case like this pr default doesn't just show as
many decimals as possible depending on the actual width of the text box? When
it is not so, I would like to know what to do to indicate a value (other than
"############") in this field whithout having to go into the field as if I
would type a new value.

I have MS Access 2007. I don't remember having the same problem with 2003,
but I am not completely sure.

I would be thankful, if anyone has a solution to this.
LarsM
 
D

Damon Heron

I have been thinking about this, and the problem is if you set the decimal
places to 3, it rounds the number.
The ###'s are there when a number exceeds the size of the field. Doesn't
work the same for text, so a kludge workaround is to make the bound txtbox
invisible, and add an unbound textbox. In the current event of the form,

Private Sub Form_Current()
Me.txtUnbound = CStr(Me.yourboundtxtbox)
End Sub
'Then in the before update event of the unbound textbox (which allows
user to change number):

Private Sub txtUnbound_BeforeUpdate(Cancel As Integer)
Me.yourboundtxtbox = CSng(Me.txtUnbound)
End Sub

Of course, you would have to have some error checking to make sure it is a
valid number.
One of the smart people on this forum will probably post a more elegant
solution, but this works....

Damon
 
D

Damon Heron

Karl,
that still rounds the number. I think LarsM wanted to see the number's
first 3 decimals without rounding. Plus he wanted to update the number if
needed.

Damon

KARL DEWEY said:
Have you tried --
MyTextDisplay: Format([MyNumberField], "0.000")

--
Build a little, test a little.


LarsM said:
In a table I have a numerical value defined as single precision. In a
form I
have a text box, where I indicate the value, and where I can also change
the
value, if I want. The value is always in the range > 0 and < 1. The text
box
is 1.2 cm (about 0.47 ") wide. With "Font Name" = "Calibri" and "Font
Size" =
11 this should give place for indicating the value wtih 4 decimals.

A correct decimal indication of a value stored with single precision can
in
princpiple have an infinite number of decimals. In the field in the form
with
limited width the value is basically shown as "############". When I go
into
the field, as if I want to change the value, the value is shown with 7
decimals, so I have to use left and right arrows (or "home" and "end") to
see
the value. If I use "home" once or "left arrow" several times, I see a
zero
followed by a decimal point and the first 3 decimals. With right arrow I
see
more decimals. As soon as I leave the field, the value is again shown as
"############". Basically I use "Decimal Places" = "Auto", but I also
tried
"Decimal Places" = 3 or 2 or 1. This didn't do any difference. I also
tried
to change some of the other "format" parameters of the text box without
result.

I wonder why MS Access in a case like this pr default doesn't just show
as
many decimals as possible depending on the actual width of the text box?
When
it is not so, I would like to know what to do to indicate a value (other
than
"############") in this field whithout having to go into the field as if
I
would type a new value.

I have MS Access 2007. I don't remember having the same problem with
2003,
but I am not completely sure.

I would be thankful, if anyone has a solution to this.
LarsM
 
L

LarsM

I tried this. It works until I try to leave the unbound field after having
typed a new value in it. Then I get the message "The field is not
updateable", and MS Access locks itself.

Even if this did work, I find it unbelivable that there isn't a simpler
solution for this simple problem. I expected it to be just a matter of
appropriate setting of one of the parameters for the field - a problem that
could easily be solved without having to do any programming.

Now I have resized the field to 1.7 cm (about 0.67 ") width. This has solved
the problem in a completely different way ;)

LarsM
 
D

Damon Heron

I was given the impression from your original posting that you had to
preserve the .47" width for some reason! Of course, I and many others would
have suggested you simply enlarge the textbox if that was an option. All I
can say is "DUUUHHH!"

Damon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top