By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,728 Members | 1,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,728 IT Pros & Developers. It's quick & easy.

Validation Rule : Only characters

P: 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
Share this Question
Share on Google+
6 Replies

JConsulting
Expert 100+
P: 603
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

P: 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
Expert 100+
P: 603
>>>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
Expert 100+
P: 603
>>>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
Expert 100+
P: 603
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
Expert 5K+
P: 8,750
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

Post your reply

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