473,386 Members | 1,602 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,386 software developers and data experts.

How to test the length of a field on data entry?

10
This seems very simple but I can't find how to do it. I wrote a form that is in data entry mode when the data is entered. The primary key field should always be a length of 5, how do I check the length and give a error if less then 5?

Thanks,
Bob
Sep 14 '10 #1

✓ answered by BobS

I was doing the text box. I changed to the before/update on the form and it worked. I guess you have to do this because I had set the data entry property of the form to 'yes'.

Thank you for your time & help.

Bob

4 2886
TheSmileyCoder
2,322 Expert Mod 2GB
Im guessing you have the user type the key? If so, you can add code to the control's BeforeUpdate. Asumming your textbox is called: tb_Primary you do like this.

Select your textbox, open the properties window, then the events tab. Find the BeforeUpdate, and click the 3 ... on the right hand side of the window, and select Event Procedure. You will now be taken to the VBA editor looking like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_Primary_BeforeUpdate(Cancel As Integer)
  2.  
  3. End Sub
Modify it to look like this, and you should be good to go:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_Primary_BeforeUpdate(Cancel As Integer)
  2.   If len(Me.tb_Primary)<>5 then
  3.     'Input error  
  4.       Msgbox "Primary Key must be 5 charecters long, please correct"
  5.     'Cancel the update of the field
  6.       Cancel=true 
  7.   End If
  8. End Sub
Sep 14 '10 #2
BobS
10
Thank you for your answer. I actually tried something similar to this under BeforeUpdate and I also tried your code also. I agree that the code will test the field length. The problem seems to be this is not executed because the form is marked as a DATA Entry (yes). I moved the code into another form where DATA Entry was marked to NO and it worked fine. Any suggestions?

Thanks,
Bob
Sep 17 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Did you use the beforeUpdate of the form or of the textbox?
Sep 18 '10 #4
BobS
10
I was doing the text box. I changed to the before/update on the form and it worked. I guess you have to do this because I had set the data entry property of the form to 'yes'.

Thank you for your time & help.

Bob
Sep 18 '10 #5

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

Similar topics

5
by: Carlos Ribeiro | last post by:
Hello all, I'm posting this to the list with the intention to form a group of people interested in this type of solution. I'm not going to spam the list with it, unless for occasional and...
2
by: Iain Miller | last post by:
Struggling a bit here & would be grateful for any help. I have a table which has a list of people in it. Each person has a unique ID automatically allocated by Access but also belongs to one of 5...
2
by: JC Mugs | last post by:
I have a form that when you tab from field to field that the entry point is blank, but if you point and click in the field it brings up a 0 and data entry is started to the left of the zero. ...
7
by: Filips Benoit | last post by:
Hi, TBL_CONTACT_PERSON CNTP_ID (auto) CNTP_LAST_NAME (required = yes) CNTP_FUNCTION (required = no) CNTP_..... (all required = no) FRM_CONTACT_PERSON_ADD_NEW Property DATA ENTRY = YES
6
by: Sami | last post by:
Problem: Social Security number being used in a database. First problem is that it will not permit numbers beginning in zero to be entered - it sees it as a null or empty space from what I can...
2
by: Kevin Myers | last post by:
Hello, Have yet another problem on a form that has me stumped. In a table that I am working with, the values for one of the fields are stored in meters. However the values that are supplied for...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
20
by: hippomedon | last post by:
Hello everyone, I'm looking for some advice on whether I should break the normalization rule. Normally, I would not consider it, but this seems to be a special case. I have created an...
3
by: imtmub | last post by:
Hi All, I am facing some problem in the field data(Description field in Item table). In that table one field(Description field)data legth is 255 and type: nvarchar. In some operation this field data...
8
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables...
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
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...
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,...
0
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...

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.