474,015 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Textboxes - Limiting decimal place entry

4 New Member
I just spent a day and a half searching forums for this solution and it does not look like it is out there yet, so I am sharing.

In access you can specify the amount of decimal places a form control displays with the Decimal Places property. You can also specify the amount of decimal places in the table design where the data is stored. Unfortunately, both of these do not limit the data at all. A control that has the decimal places property set to 2 can have an entry of 1.23456! Access accepts the entry.

This was killing some of my form calculations. I needed a solution that would not cause other events to fire, which is what happens if you simply alter the value of a control OnExit by using Round(). I also needed a solution that I could easily implement on 360 textboxes across 6 forms. Writing a Sub for each the limited keystrokes was not going to happen.

Solution:

Private Sub Form_KeyPress(K eyAscii As Integer)
If InStr(1, Me.Controls(Me. ActiveControl.N ame).Text, ".") <> 0 Then
If Me.Controls(Me. ActiveControl.N ame).SelStart >= InStr(1, Me.Controls(Me. ActiveControl.N ame).Text, ".") Or Me.Controls(Me. ActiveControl.N ame).SelStart >= InStr(1, Me.Controls(Me. ActiveControl.N ame).Text, ".") + 1 Then
If Len(Me.Controls (Me.ActiveContr ol.Name).Text) = InStr(1, Me.Controls(Me. ActiveControl.N ame).Text, ".") + 2 Then
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
ElseIf Me.Controls(Me. ActiveControl.N ame).SelStart >= InStr(1, Me.Controls(Me. ActiveControl.N ame).Text, ".") + 2 Then
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
End If
End Sub

The code above is fired from the FORM’s KeyPress event and acts on all controls on the form. It determines the Text value of the ActiveControl and the cursor location in the control. Using these, it will allow or ignore the keypress based on the cursor location relative to the location of the "."

To work, the Key Preview property of the form also needs to be set to Yes.

Hope this helps somebody.
May 25 '10 #1
0 3605

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3823
by: intl04 | last post by:
Is it possible to create a Word form as the data entry form for an Access database? I didn't see any reference to this possibility in my Access books, so I'm sorry if this is a question that is rather off-the-wall. I was asked to ask this question, to see if a Word form can be linked to an Access database and then emailed to various end-users for them to complete task requests using this form.
1
3195
by: martin | last post by:
Hi, I am having difficulty trimming any traling 0's from my decimal numbers. I store then in the database to 2 decimal places. This means that when they come back to my application they still diply with all the decimal places eg 10.00 displays as 10.00
1
1938
by: Ken | last post by:
HI all I would like to round up a double number, for example, 100.689 and round up to 100.6 i know i can do it with Round function. However, it doesn't show the any decimal place if the number is 100. I would like to show the decimal places even though they are 100.00. Thanks
0
1886
by: pomeroymiles | last post by:
I have a pivotchart which I cause to take a huge list of people's test percentiles and calculate the average for each year. I then display the average above each bar. The problem is that there are too many numbers after the decimal place for each figure. I went into the properties and changed the number format to "fixed" but it doesn't give me the option to change the number of decimal places that are used (it does every where else in MS...
3
9801
by: flickimp | last post by:
Hi Got various fields in T-SQL where a decimal point and a zero follows each value: ie: 46.0 54.0 234.0
2
2464
by: DamSexy | last post by:
Im doing some work for uni and I am a beginner at javascript. This is the code that I have: var canvas; canvas = openGraphics(); var radius; radius = 20; var area; area = (radius*radius)*Math.PI;
3
2751
by: George Eapen | last post by:
Hi all, i want to check whether a value entered into a specific html field is numeric as well as should contain one decimal value.( eg.23 is not accepted..It should be 23.0) i have come up with a code which checks whether the value is numeric or not. But how can i check for decimal place..Any one who can help me on this? Thanks in Advance
1
2197
by: maharajakecil | last post by:
hello VB expertise. how should i modify my source code if i want change my X and Y value into one decimal place like 1.2,1.3,1.4 and so on. thank for the help. i really appreciate it! Private Sub Form_Load() Dim Xvalue As Long Dim Yvalue As Long For Xvalue = 0 To 15 cboXvalue.AddItem CStr(Xvalue) Next Xvalue
1
7956
by: chinni0719 | last post by:
Can you plz tell me how to truncate zeros after decimal the case is like this round(992.55,0) result =993.00 round(993.888) result = 994.000
5
5350
by: MyWaterloo | last post by:
I need to change the decimal value in one of my databases. Currently my company uses an ID system with nice whole numbers, i.e. no decimal numbers. Now my boss has this grand scheme to start using decimals. 1.17.1 etc. I can't seem to be able to get my table and form to accept the change??? In my table I currently changed the "Decimal Places" to 2 and the "Format" to "General Number". I then tell it to update format everywhere the ID is...
0
10282
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
11053
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10217
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7766
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6731
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3900
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.