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!

Prevent users from entering fractions of pennies in Currency Fields

Status
Not open for further replies.

egstatus

Programmer
Apr 14, 2005
143
0
0
US
Ho do I prevent users from entering fractions of pennies in currency fields?

I am using currency as the field type and I have 2 decimal places as the number of decimal places. However the user can type more that 2 decimals @2.3572 for example. Even though when they leave the field the field shows $2.35. When you click on the field it show the $2.3572. When I check the data that is saved, the table displays it at 2.35 but when you click on the field it shows it as 2.3572 (4 decimal places)
I need to prevent the user from entering fractions of pennies. It is causing issues with our calculations.

I'm sure this is doable I just can't figure it out.

Thanks in advance

Egstatus
 
The no-code solution is to use an Input Mask it you can get it to match your requirements.

Here is a kludgy code solution. I expect there might be something easier:

Code:
Private Sub Text2_Change()
    Dim strText As String
    strText = Me.Text2.Text
    If InStr(strText, ".") > 0 Then
        If InStr(strText, ".") < Len(strText) - 2 Then
            Me.Text2 = Left(strText, Len(strText) - 1)
            Me.Text2.SelStart = Len(strText) - 1
            Beep
        End If
    End If
End Sub
Duane
Hook'D on Access
MS Access MVP
 
Thanks Duane, That does the trick. Never occurred me to go that way.

One more question.( I don't know if I should start a new thread for this question).

I have a Yes/No Field. I store the values as -1/0.
I display the field in a combobox and they are displayed as Yes/No. The combo box has a list value with 2 entries, "Yes" and "No" with a Default of 'No'. Entering the information in the field work as intended, However if I click inside the field I see either a 0 or -1. As soon as I leave the field the field displays either Yes/No. How can I prevent showing 0/-1 when user clicks inside the field?

Any Idea why access shows 0 or -1 if I click inside the form's field?

Thanks

EGStatus

 
I would start a new thread for this question since it does not relate to the original question.

BTW - did you consider a checkbox instead of a combo box?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top