By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

Formatting a Decimal number in Unbound field

P: n/a
I am trying to format a number in an unbound text field using the
following format statement in the field's Exit event:

txt11UnitWeight = Format(txt11UnitWeight, "00000.00")

I want the number to the left of the decimal to be 5 digits long, left
zero filled and 2 digits to the right of decimal.

Entering a number such as 12345 will get me the required 12345.00. If
I have a number such as 1234525, I want the program to format the
number as 12345.25, however, what I am getting is 1234525.00.

The folling is the code in my KeyPress event that I am using to limit
the input:

'Limit input to numbers
If (KeyAscii > vbKeySpace And KeyAscii < vbKey0) Or KeyAscii > vbKey9
Then
KeyAscii = 0
Else
'Determine if field has a decimal point already (from format stmt)
strpos = InStr(txt11UnitWeight.Text, ".")
textlen = Len(txt11UnitWeight.Text)
If (strpos = 0 And (textlen - txt11UnitWeight.SelLength) = 7) Or _
(strpos > 0 And (textlen - txt11UnitWeight.SelLength = 8)) Then
'allow backspace character
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
Thanks in advance

Stuart
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You want to divide the number by 100 if there are more than 5 digits and no
decimal point?

Private Sub txt11UnitWeight_AfterUpdate()
With Me.txt11unitWeight
If Len(.Text) > 5 Then
If InStr(.Text", ".") = 0 Then
.Value = .Value / 100
End If
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"stuart" <st***********@ncmail.net> wrote in message
:20**************************@posting.google.com.. .
I am trying to format a number in an unbound text field using the
following format statement in the field's Exit event:

txt11UnitWeight = Format(txt11UnitWeight, "00000.00")

I want the number to the left of the decimal to be 5 digits long, left
zero filled and 2 digits to the right of decimal.

Entering a number such as 12345 will get me the required 12345.00. If
I have a number such as 1234525, I want the program to format the
number as 12345.25, however, what I am getting is 1234525.00.

The folling is the code in my KeyPress event that I am using to limit
the input:

'Limit input to numbers
If (KeyAscii > vbKeySpace And KeyAscii < vbKey0) Or KeyAscii > vbKey9
Then
KeyAscii = 0
Else
'Determine if field has a decimal point already (from format stmt)
strpos = InStr(txt11UnitWeight.Text, ".")
textlen = Len(txt11UnitWeight.Text)
If (strpos = 0 And (textlen - txt11UnitWeight.SelLength) = 7) Or _
(strpos > 0 And (textlen - txt11UnitWeight.SelLength = 8)) Then
'allow backspace character
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
Thanks in advance

Stuart

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.