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

Validation Rule : Only characters

2
I want to ensure that a field contains only Characters without numbers .... Do you know the validation rule ? thank you ! ( I'm new at ms access)
May 24 '07 #1
6 4877
JConsulting
603 Expert 512MB
I want to ensure that a field contains only Characters without numbers .... Do you know the validation rule ? thank you ! ( I'm new at ms access)
put this in your text box's Before_Update event and change the name where appropriate to your textbox.
J

Expand|Select|Wrap|Line Numbers
  1. dim j as integer
  2. '---- loop through characters is box ----
  3. for j = 1 to len(me.textbox.text)
  4.      '------ look for anything not acceptable -------------------------
  5.     if mid(me.textbox.text,j,1) < "A" or mid(me.textbox.text,j,1) > "Z" THEN
  6.             '--- if found - warn user ------------------
  7.          msgbox "Enter Warning Message Here"
  8.          cancel=true
  9.            exit for
  10.     end if
  11. next j
  12.  
  13.  
May 24 '07 #2
yaks
2
>>>Private Sub Name_BeforeUpdate(Cancel As Integer)<<<
It gets yellow and it says that i have a bug... :/ any solutions?


Dim j As Integer
'---- loop through characters is box ----
For j = 1 To Len(Me.Name.Text)
'------ look for anything not acceptable -------------------------
If Mid(Me.Name.Text, j, 1) < "A" Or Mid(Me.TextBox.Text, j, 1) > "Z" Then
'--- if found - warn user ------------------
MsgBox "It must contain only characters"
Cancel = True
Exit For
End If
Next j

End Sub
May 24 '07 #3
JConsulting
603 Expert 512MB
>>>Private Sub Name_BeforeUpdate(Cancel As Integer)<<<
It gets yellow and it says that i have a bug... :/ any solutions?


Dim j As Integer
'---- loop through characters is box ----
For j = 1 To Len(Me.Name.Text)
'------ look for anything not acceptable -------------------------
If Mid(Me.Name.Text, j, 1) < "A" Or Mid(Me.TextBox.Text, j, 1) > "Z" Then
'--- if found - warn user ------------------
MsgBox "It must contain only characters"
Cancel = True
Exit For
End If
Next j

End Sub

>>Private Sub Name_BeforeUpdate(Cancel As Integer)

Replace Name with the name of your textbox. If your textbox is called name...rename it to txtName and use that.
J
May 24 '07 #4
JConsulting
603 Expert 512MB
>>>Private Sub Name_BeforeUpdate(Cancel As Integer)<<<
It gets yellow and it says that i have a bug... :/ any solutions?


Dim j As Integer
'---- loop through characters is box ----
For j = 1 To Len(Me.Name.Text)
'------ look for anything not acceptable -------------------------
If Mid(Me.Name.Text, j, 1) < "A" Or Mid(Me.TextBox.Text, j, 1) > "Z" Then
'--- if found - warn user ------------------
MsgBox "It must contain only characters"
Cancel = True
Exit For
End If
Next j

End Sub
also, read through the code, there are other places where you need to change the name of the textbox.
J
May 24 '07 #5
JConsulting
603 Expert 512MB
also, read through the code, there are other places where you need to change the name of the textbox.
J
change the name of your textbox to txtName
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtName_BeforeUpdate(Cancel As Integer)
  2. Dim j As Integer
  3. '---- loop through characters is box ----
  4. For j = 1 To Len(Me.txtName)
  5. '------ look for anything not acceptable -------------------------
  6. If Mid(Me.txtName, j, 1) < "A" Or Mid(Me.txtName, j, 1) > "Z" Then
  7. '--- if found - warn user ------------------
  8. MsgBox "It must contain only characters"
  9. Cancel = True
  10. End If
  11. Exit For
  12. Next j
  13. End Sub
  14.  
May 24 '07 #6
ADezii
8,834 Expert 8TB
I want to ensure that a field contains only Characters without numbers .... Do you know the validation rule ? thank you ! ( I'm new at ms access)
This is a code free, very easy, and probably the most efficient solution, since it limits the entry into a Field to only Characters at the Table Level. If you have multiple Forms each referencing this Field, you would have to duplicate the Validation Code, whereas setting the Input Mask at the Table Level will be universal. You would not even be able to enter a number in the Field making this approach pro-active instead of reactive. Set The Input Mask of your Field in Table Design View to the following. The actual number of ?s is irrelevant as long as there is 1 more ? than the longest possible entry. If you need further explanation, let us know:
Expand|Select|Wrap|Line Numbers
  1. ?????????????????????????????????;1;" "
May 25 '07 #7

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

Similar topics

2
by: Dalan | last post by:
This ought to be simple enough, but not certain which to use. I have a few fields set to Require data to be entered; however, the message displayed by Access 97 is too generic to be of any real...
2
by: Doslil | last post by:
I am trying to validate the fields in my database.I have already validated the fields to check for not null.Here is what I have written for Numeric and text field. Private Function EENUM() On...
4
by: Ben | last post by:
Hi all, In my STUDENT table, I have a field called STUDENT_NAME. I want the data in this field to be only alphabets with allowance for ' and - ,but nothing else- no digits, no other special...
7
by: Mathew Hill | last post by:
I am a beginner to the more technical aspects of Microsoft Access (2000) and was wondering if any one can help? I have a field in a table called: ADMIN NUMBER This field should have 4...
7
by: Tom | last post by:
How do I set up the following Validation Rules in a table: 1. Two chars - both must be digits(0-9) 2. Three characters - first character must be a letter 3. 6 characters - all must be...
1
by: toby989 | last post by:
Hi All I was wondering how a emailaddress validation rule looks like. I was hoping that either a wizard that offers example fileds or the example database that comes with access would provide...
6
by: bluray | last post by:
Hello all, and thanks for taking the time to help me out here. Basically, I am trying to set up a validation rule that correlates with an input mask where the user is required to enter select...
4
by: killuminati | last post by:
Hi there. I am studying ICT at a college in cumbria. I have been trying to get a validation rule set-up which allows me to enter alpha characters only, but hypens and apostrophes are allowed. I have...
1
by: bruce.dodds | last post by:
I would like to set up a field validation rule to limit first name characters to alphabetic characters, period, and space. I've tried a number of variations on this rule: Is Null Or...
7
by: sharsy | last post by:
Hi guys, I would like to setup a validation rule for a database in microsoft access that restricts data entry so that a certain field can only be filled in if another field has a specific answer...
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?
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...
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
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...

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.