Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fixed decimal on a form

Status
Not open for further replies.
Oct 11, 2002
28
0
0
US
We have developed a database to collect food charges. What we'd like to do is have users type a number like 534 into the form, but the form will register and display 5.34. How do I create a field on the form that will display a decimal point that will stick and let the numbers typed in float over it?

Thanks in advance,
Devin
 
Float over? I think I know what you mean...but an alternative is to divide by 100 (provided that 2 decimal places are ALWAYS entered).

eg. [Text1].Value = [Text1].Value / 100
{could be inserted into your AfterUpdate Event}

Using an appropriate 'mask' this would easily be acheivable. The dowside is that you won't have a decimal point.

If you still want to make the decimal point 'float' how would you know when a value reaches the first decimal place?
[yinyang]
 
The AfterUpdate Event may work for us, but I have an additional question. At what point would the user see that decimal point appear? Would it just feed into the system when the record is saved? Or would it appear when the user moves to another field?

We wouldn't know when a value reaches the first decimal place. I've seen this static decimal point happen in many retail systems, but we have not been able to find any documentation about how to make that work in Access.

As a user types in a number (ex. $6.42), this is how the field looks (in certain retail systems) as each number is typed:
. 6
.64
6.42

This was just a user request, since this is what they were used to before coming here. I had thought about putting a picture of a decimal point on the form and then parsing in a decimal place as the number goes back into the system.

Devin
 
Try putting this code into your Text Box's "On Change" event:

code begins---------------

'Change Text1 to the 'name' of your own text box.
On Error Resume Next
Dim DecPlace As Integer
Dim Check As String
Refresh
DecPlace = InStr(1, Text1, ".", 1)
If DecPlace <> 0 Then Text1 = Left(Text1, DecPlace - 1) & Trim(Right(Text1, Len(Text1) - DecPlace))
Select Case Len(Text1)
Case 1
Text1 = &quot;. &quot; & Text1
Case 2
Text1 = &quot;.&quot; & Text1
Case Is > 2
Text1 = Left(Text1, Len(Text1) - 2) & &quot;.&quot; & Right(Text1, 2)
End Select

DecPlace = InStr(1, Text1, &quot;.&quot;, 1)
If DecPlace <> 0 Then Check = Left(Text1, DecPlace - 1) & Trim(Right(Text1, Len(Text1) - DecPlace))
If IsNumeric(Check) = False Then MsgBox &quot;Not a Number!&quot;
Text1.SelStart = Len(Text1)

code ends---------------

The only downfall with the above code is that you MUST make it accept ALL textual values (not just digits) to allow for the decimal character. So, I have put in a simple check to see if the value is numeric...you could expand on this if desired or completely disregard it - its up to you. You may also have to leave it unbound and simply link it to the original bound field, but that shouldn't be to big a drama.

Hope this is what you're looking for
[yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top