Solved

Currency format

Posted on 1998-12-27
5
196 Views
Last Modified: 2010-05-03
I am having problem in Currency format.  How can I avoid the user to input the decimal point(.) twice?

For example: 102.102.05

This might bugs the system when performing calculation.  I don't want to trap this by using message box but I mean to say is that not allow the user to input the second decimal point when it was press in the keyboard.  I am using MS Access97 as my database.  I use the field type, Currency in database but it doesn't seems trapping the decimal point when user input.  I also use this format:

     unitprice.Text = Format(unitprice.Text, "#,###,###.00")

But still doesn't work.  Hope to hear any comments from you.

Thank you very much.
0
Comment
Question by:tins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Sendoh
ID: 1452617
Hi !

try following code :

Private Sub Text4_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 110 Then
        If InStr(Text4.Text, ".") <> 0 Then
            KeyCode = 0
        End If
    End If
End Sub

Hope it'll help you !!
0
 

Author Comment

by:tins
ID: 1452618
Thanks Sendoh!  Regarding Sendoh's answer, this is working when I scan the code while running through break points. But when I left it all the way to run, it doesn't work.  I don't know why it is that way, any comment?  
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1452619
put the same code provided by sendoh in the keypress event ,

Note: keep it in the key down event

0
 
LVL 3

Accepted Solution

by:
Sendoh earned 10 total points
ID: 1452620
Opps !
The correct way should be this :

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Dim str As String
   
    str = Text1.Text
    If KeyAscii = 46 Then
        If InStr(str, ".") <> 0 Then
            KeyAscii = 0
        End If
    End If
End Sub

Hope it'll suite you !!

0
 

Author Comment

by:tins
ID: 1452621
Thank you very much Sendoh!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question