473,412 Members | 5,361 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,412 software developers and data experts.

Field validations

1
hi everyone, i am currently in the process in making a database for my a-levels coursework in ict, i am a begginner to microsoft access and i am really stuck at the momemt,

in my database i have to validate fields where some fields only accept alphabets and some only accept numbers and just cant figure out how to do it, i'v looked all over the internet but just cant find any help.

can someone please help me and tell me how to do this asap.

THANK YOU
Jan 23 '07 #1
4 6387
nico5038
3,080 Expert 2GB
You can use an input mask for this.
Just check the helpfile for the available codes.

For numeric fields just use a numeric fieldtype.

Nic;o)
Jan 23 '07 #2
missinglinq
3,532 Expert 2GB
Are these fields that "only accept numbers" actually numerical fields? A numerical datatype, such as Integer or Long or Double, should only be used if you're actually going to use them as numbers, which is to say doing math with them. If it's just a field that needs to accept only numerical characters, such as an ID number or a Parts number, you should use a text datatype.
Jan 23 '07 #3
ADezii
8,834 Expert 8TB
hi everyone, i am currently in the process in making a database for my a-levels coursework in ict, i am a begginner to microsoft access and i am really stuck at the momemt,

in my database i have to validate fields where some fields only accept alphabets and some only accept numbers and just cant figure out how to do it, i'v looked all over the internet but just cant find any help.

can someone please help me and tell me how to do this asap.

THANK YOU
To expand on Nico5038's response, the following characters define an Input Mask:
Character - Description
0 - Digit (0 to 9, entry required, plus [+] and minus [–] signs not allowed).
9 - Digit or space (entry not required, plus and minus signs not allowed).

# - Digit or space (entry not required; spaces are displayed as blanks while in Edit mode, but blanks are removed when data is saved; plus and minus signs allowed).

L - Letter (A to Z, entry required).
? - Letter (A to Z, entry optional).
A - Letter or digit (entry required).
a - Letter or digit (entry optional).
& - Any character or a space (entry required).
C - Any character or a space (entry optional).

. , : ; - / Decimal placeholder and thousand, date, and time separators. (The actual character used depends on the settings in the Regional Settings Properties dialog box in Windows Control Panel).

< - Causes all characters to be converted to lowercase.
> - Causes all characters to be converted to uppercase.

! - Causes the input mask to display from right to left, rather than from left to right. Characters typed into the mask always fill it from left to right. You can include the exclamation point anywhere in the input mask.

\ - Causes the character that follows to be displayed as the literal character (for example, \A is displayed as just A).

Examples:
LLLLLL - 6 Letters [A-Z] are 'required'
AAAAAA - 6 Letters or Digits are 'required'

NOTE: Select the Input Mask Field for a Field in Table Design View on the bottom Pane and press F1
Jan 24 '07 #4
missinglinq
3,532 Expert 2GB
Like a lot of people I try to stay away from input masks as a rule; they can be messy and require extra work if users click into the field rather than tabbing into it. But input masks would do the job. The poster's statement
in my database i have to validate fields where some fields only accept alphabets and some only accept numbers
combined with the fact that this is a class project makes me wonder if the instructer specifically wants the fields to be validated, as an instructional gimmick.

If the field is defined in the table as numerical, Access itself will indicate that there's a problem if non-numerical data is entered. It pops up a rather inelegant error message stating that the data is inappropriate. The usual way of turning off Access' messages (DoCmd.SetWarnings False) doesn't work here.

If the field's datatype is actually Text and you simply want to insure that all the characters are numerical you can use the IsNumeric function:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Numbers_BeforeUpdate(Cancel As Integer)
  2.  
  3. 'This insures that all characters are Numbers
  4. If Not IsNumeric(Me.Numbers.Value) Then
  5.    MsgBox "All characters must be Numbers"
  6.    Cancel = True
  7.    Me.Numbers.SelStart = 0
  8.    Me.Numbers.SelLength = Len(Me.Numbers.Value)
  9.  End If
  10. End Sub
  11.  
Unlike Excel, there is no IsText function in Access. Since Access allows alpha and numeric characters in Text fields, you can't use the opposite logic with IsNumeric, you have to loop thru the field one character at a time and check whether or not each one is numeric.
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Letters_BeforeUpdate(Cancel As Integer)
  2. Dim I As Integer
  3. Dim Hits As Integer
  4. Hits = 0
  5. 'This insures that all characters are Letters
  6.  
  7. For I = 1 To Len(Me.Letters.Value)
  8.  If IsNumeric(Mid(Me.Letters.Value, I, 1)) Then
  9.    Hits = Hits + 1
  10.  End If
  11. Next I
  12.  
  13.  If Hits > 0 Then
  14.    MsgBox "All characters must be Letters"
  15.    Cancel = True
  16.    Me.Letters.SelStart = 0
  17.    Me.Letters.SelLength = Len(Me.Letters.Value)
  18.  End If
  19. End Sub
Jan 24 '07 #5

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

Similar topics

3
by: Shabam | last post by:
I know that dotnet allows for form field validation. However I'm looking to customize the error message display and am wondering if it's possible to do what I need. Example: Suppose in a...
3
by: Jenni | last post by:
Sorry about the unwieldy title, it's difficult to describe it in any other way. Basically I have a table in Access 97 which contains a number of records in different states. When originally...
2
by: Jan | last post by:
Hi all, I have got the following problem: User fills in excel sheet, this is loaded in Acces. After this I run a validation tool to validate the field formats. One fields is allowed to be...
3
by: Rick | last post by:
I have an interesting problem when I run the following code in Netscape (7.02) vs. IE. This page works great in IE and all my controls bring up the validation summary dialog box if the required...
6
by: Paul | last post by:
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side...
1
by: anil kumar via .NET 247 | last post by:
(Type your message here) hi, i am using save & cancel webform buttons in my webpage to withsome validations , when i am trying to save my content it issaved that time i need a popup msg like ur...
1
by: Anup | last post by:
In my form I and doing validations using 'Javascript' as I m using ASP1.1 and there is very less support for Validators there. //Code Behind private void Page_Load(object sender,...
10
by: canam | last post by:
Hi: I hope someone can help me. Is there a way to add a password to a particular field in the event that the validation rule must be over written? I've created an input form in a...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
2
by: prakashsurya | last post by:
Hello I am going through the validations in a form I would like to know the validations to be considered in writing javascript for email id so would u plz help me in writing the necessary...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.