473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Validation based on numeric type Access 2003

I have a text box field that is used for putting in the size in inches of a product we sell. We have several different products that use the same box and all but one group can have decimals 2.25 (as an example). However we have one group that must be to the nearest inch.

What I would like is for the validation to pop up if the user enters a decimal that warns them it's not available and prompts them to correct it. I have the validation and the top and bottom limiters but I cannot figure out how to validate for a decimal entry.

below is my current code:

Expand|Select|Wrap|Line Numbers
  1. Case 6, 7 'product 1 and product 2
  2.  
  3.         sngheight = Int(frm.TxtDoorHt.Value / 12)
  4.         sngwidth = Int(frm.TxtDoorWidth.Value / 12)
  5.  
  6.         If (frm.TxtDoorHt.Value >= 78 And frm.TxtDoorHt.Value <= 126) Then
  7.             bInvalidSize = False
  8.         Else
  9.             bInvalidSize = True
  10.         End If
  11.         If (frm.TxtDoorWidth.Value >= 48 And frm.TxtDoorHt.Value <= 222) Then
  12.             bInvalidSize = False
  13.         Else
  14.             bInvalidSize = True
  15.         End If
Feb 13 '13 #1

✓ answered by Mikkeee

You could restrict certain characters from being entered. Having the following code in the KeyPress event of your text box should do it.

Expand|Select|Wrap|Line Numbers
  1. ' Eat the decimal key
  2. If KeyAscii = 46 Then
  3.     KeyAscii = 0
  4. End If
  5.  
But if you really have your heart set on checking for a decimal then this will do it.
Expand|Select|Wrap|Line Numbers
  1. If InStr(frm.TxtDoorHt.Text, ".") > 0 Then
  2.     Debug.Print "Found It"
  3. End If
  4.  

6 1554
Mikkeee
94 64KB
You could restrict certain characters from being entered. Having the following code in the KeyPress event of your text box should do it.

Expand|Select|Wrap|Line Numbers
  1. ' Eat the decimal key
  2. If KeyAscii = 46 Then
  3.     KeyAscii = 0
  4. End If
  5.  
But if you really have your heart set on checking for a decimal then this will do it.
Expand|Select|Wrap|Line Numbers
  1. If InStr(frm.TxtDoorHt.Text, ".") > 0 Then
  2.     Debug.Print "Found It"
  3. End If
  4.  
Feb 13 '13 #2
Thank you, I used the first options and it might work for probably 90 percent of the situation. The problem 10 percent is as follows:

The users first picks Product 1 which allows decimals
Then they enter the dimensions in feet and inches for both height and width, let's say 4 feet 2.25 inches

If they want to change the product line, we have it set to keep the existing dimension to make the program more user friendly the dimensions are left in there. (fewer keystrokes = greater efficiency)

Since Product 1 has decimals in the inches field and Product 2 cannot, how do I have it pop up a message when there is an invalid decimal entry for Product 2?

I hope I making this clear, this is a pretty complex Access Program that we use to configure all our products for pricing purposes so it's quite cumbersome, and I'm trying to keep it as user friendly as possible. So ideally wiping out the dimensions would be the last choice.
Feb 13 '13 #3
Mikkeee
94 64KB
Mayala, I partially agree with you (fewer keystrokes = greater efficiency) until you get to the part where you're allowing invalid data in the text boxes. I would (now this is just my opinion here) allow the user to switch the product but I would clean up the data to make it valid. In your example, the user entered 2.25 in one product but the second won't allow the decimal. I would either truncate or round that 2.25 to 2. If you want the user to see the 2.25 when they switch back then you should save the last valid entry in a variable that way you knew that it was 2.25, modified to display 2, and then grab that 2.25 from your variable and put it back in there. There are many different ways to accomplish this but I don't believe knowingly displaying an invalid entry is the right way to go.
Feb 13 '13 #4
Rabbit
12,516 Expert Mod 8TB
Use an additional Case statment and check if they entered a decimal in the textbox.
Feb 13 '13 #5
Thank you all for your help on this, I have been given further direction that allows for the first answer with the code to initially prevent decimals to be adequate, anything after that will be handled by the processes we have in place so Yay, no coding required. But the help on that code to prevent the decimals will be very useful, so thanks again!
Feb 14 '13 #6
Killer42
8,435 Expert 8TB
Just a suggestion. Don't simply "eat" the decimal point. That just makes entry confusing for the user, because they think they've typed (for example) "2.3" but actually entered 23. At the very least, it should beep to get their attention.

Although it can be a bit fiddly to code, in a situation like this I actually like to beep and do something visual (such as change the border colour around the field) for a second or two. Oh. This is Access? This sort of effect may be even more fiddly there than in VB6. But I'm sure it's still possible.

Another nice option, interface-wise, is to make the field stand out visually as long as the value in it isn't valid. For example, in an event that fires every time the field changes (.Change, .Validate or whatever) you simply set the background colour of the field to red if not currently valid, or normal otherwise. Ideally, this also happens whenever the situation changes (such as changing the product type) so that it's immediately obvious that the value already sitting there no longer fits.

P.S. I realise this thread's sort of old now, but hopefully these ideas might benefit anyone else who comes looking for similar answers.
Feb 19 '13 #7

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

Similar topics

2
by: SHC | last post by:
Hi all, I ran the attached volcanoes.xml (with geology.dtd) in the Module of Access 2003. I got the following error: Microsoft Office Access You have error Invalid Character in content model....
1
by: Matt Alanzo | last post by:
On another newsgroup an Access knowledgable party posted: >You should be able to connect an Access ADP to an existing SQLExpress >database running in SQLS 2000 compatibility mode. The only thing...
0
by: David G. | last post by:
The keyboard type ahead buffer does not seem to work in Access 2003 in certain situations. We would like some help with this. Here are the details. We have a large program that was developed...
0
by: neoteny2 | last post by:
I need MS Access to automatically create reports/subreports based on specific criteria. I am building a database in Access 2003 with different locations/sites. I have the "sites" table created...
6
by: Donald Grove | last post by:
I do programming in Access 2000 and 2003. I don't have a copy of 2003 myself, though. I have read about the adp software that comes with Access 2003, that converts an application to an access...
3
by: aris1234 | last post by:
Hi.. i have field in record using type : numeric, how to make validation and i want viewing messagebox if user inputing character or empty? this code just work for empty field, not for numeric...
0
by: auxvivrespos | last post by:
I am using Access 2003 and I have built a simple little database to keep track of invoices that are received at my office. I have created a "Suppliers" table which is a list of the companies from...
9
by: Axxe | last post by:
I have searched high and low for cogent, well-explained coding to complete a project on which I have spent six months of work. I stumbled across something on this site that is close to what I...
4
by: daved | last post by:
SOLUTION NEEDED FOR ACCESS 2003 / VBA, NOT FOR ANY VERSION OF VB. I need to differentiate between the Enter key on the main keyboard and the numeric keypad and obviously tried using...
2
stonward
by: stonward | last post by:
I have to update a form based on old(!) Access 2003 - in particular I need to replace the old DatePicker control with a proper calendar control. I have Calendar 12, but it's always maximised. So have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.