I have a combobox that gets it's values from a field in a table. Limit to
list and auto-expand are both set to true. The (desired) validation rule is
that the entry must be a 6 digit number (String) and not contain any letters
or special characters. If I use an input mask, it kills the auto fill-in
behavior that I want by forcing the user to click at the exact left hand
side of the text box portion of the combo box. Also, it fills in the first
entire number it finds as soon as they type the first character, whereas I
want Access to fill in the number as they enter it. Is there a way to write
a validation rule that will check that the number is 6 characters in length
and will make sure that they enter only numbers, no letters or special
characters? I've written code that checks for length, but how do I check for
numbers only?
Thanx,
Rip
|
|
0
|
|
|
|
Reply
|
RipperT
|
7/17/2007 1:03:04 AM |
|
You could set the Validation Rule of the combo to:
Is Null OR Not Like "*[!0-9]*"
More examples of validation rules:
http://allenbrowne.com/ValidationRule.html
Another approach would be to set the combo's On KeyDown event property to:
[Event Procedure]
Click the Build button beside that.
Access opens the code window.
Between the "Private Sub..." and "End Sub" lines, enter this line:
Call DigitOnly(KeyAscii)
Now create a new module (Modules tab of Database window, and click New.) In
the new code window paste the procedure below.
What it does is to destroy all keystrokes except digits and the backspace
character. Any other key is just ignored. (A side effect is that hotkeys
such as Alt+Z to jump to another field do not work while you are in the
combo.)
Public Sub DigitOnly(KeyAscii As Integer)
On Error GoTo Err_DigitOnly
'Purpose: Disallow any keystroke except 0 ~ 9, and backspace.
'Usage: In a text box's KeyDown event procedure:
' Call DigitOnly(KeyAscii)
If KeyAscii < 48 Or KeyAscii > 57 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
End If
End If
Exit_DigitOnly:
Exit Sub
Err_DigitOnly:
Msgox Err.Description
Resume Exit_DigitOnly
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"RipperT" <rippert@nOsPaM.net> wrote in message
news:%23ESW94AyHHA.4652@TK2MSFTNGP05.phx.gbl...
>I have a combobox that gets it's values from a field in a table. Limit to
>list and auto-expand are both set to true. The (desired) validation rule is
>that the entry must be a 6 digit number (String) and not contain any
>letters or special characters. If I use an input mask, it kills the auto
>fill-in behavior that I want by forcing the user to click at the exact left
>hand side of the text box portion of the combo box. Also, it fills in the
>first entire number it finds as soon as they type the first character,
>whereas I want Access to fill in the number as they enter it. Is there a
>way to write a validation rule that will check that the number is 6
>characters in length and will make sure that they enter only numbers, no
>letters or special characters? I've written code that checks for length,
>but how do I check
> for numbers only?
|
|
0
|
|
|
|
Reply
|
Allen
|
7/17/2007 1:32:55 AM
|
|
Hi, Allen,
Thanks for the response. The validation rule you suggest is completely
ignored, as are my other attempts at validation rules.There must be other
code interfering. I have code that fires in the BeforeUpdate, AfterUpdate
and NotInList events. I'm not sure of the order of events, but would they be
interfering? Anything I type in the validation rule box in properties just
goes unnoticed by Access. Everything else works.
Also, the Sub DigitOnly and the call to it generated an error:
Compile error:
ByRef argument type mismatch
The code for the call looks like this:
Private Sub InmateId_KeyDown(KeyCode As Integer, Shift As Integer)
Call DigitOnly(KeyAscii)
End Sub
I don't know if maybe the two builder generated arguments have something to
do with it?
Thanks again,
Rip
"Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
news:OwpFoJByHHA.140@TK2MSFTNGP02.phx.gbl...
> You could set the Validation Rule of the combo to:
> Is Null OR Not Like "*[!0-9]*"
> More examples of validation rules:
> http://allenbrowne.com/ValidationRule.html
>
> Another approach would be to set the combo's On KeyDown event property to:
> [Event Procedure]
> Click the Build button beside that.
> Access opens the code window.
> Between the "Private Sub..." and "End Sub" lines, enter this line:
> Call DigitOnly(KeyAscii)
>
> Now create a new module (Modules tab of Database window, and click New.)
> In the new code window paste the procedure below.
>
> What it does is to destroy all keystrokes except digits and the backspace
> character. Any other key is just ignored. (A side effect is that hotkeys
> such as Alt+Z to jump to another field do not work while you are in the
> combo.)
>
> Public Sub DigitOnly(KeyAscii As Integer)
> On Error GoTo Err_DigitOnly
> 'Purpose: Disallow any keystroke except 0 ~ 9, and backspace.
> 'Usage: In a text box's KeyDown event procedure:
> ' Call DigitOnly(KeyAscii)
>
> If KeyAscii < 48 Or KeyAscii > 57 Then
> If KeyAscii <> vbKeyBack Then
> KeyAscii = 0
> End If
> End If
>
> Exit_DigitOnly:
> Exit Sub
>
> Err_DigitOnly:
> Msgox Err.Description
> Resume Exit_DigitOnly
> End Sub
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "RipperT" <rippert@nOsPaM.net> wrote in message
> news:%23ESW94AyHHA.4652@TK2MSFTNGP05.phx.gbl...
>>I have a combobox that gets it's values from a field in a table. Limit to
>>list and auto-expand are both set to true. The (desired) validation rule
>>is that the entry must be a 6 digit number (String) and not contain any
>>letters or special characters. If I use an input mask, it kills the auto
>>fill-in behavior that I want by forcing the user to click at the exact
>>left hand side of the text box portion of the combo box. Also, it fills in
>>the first entire number it finds as soon as they type the first character,
>>whereas I want Access to fill in the number as they enter it. Is there a
>>way to write a validation rule that will check that the number is 6
>>characters in length and will make sure that they enter only numbers, no
>>letters or special characters? I've written code that checks for length,
>>but how do I check
>> for numbers only?
>
|
|
0
|
|
|
|
Reply
|
RipperT
|
7/18/2007 12:30:02 AM
|
|
The Validation Rule of the text box fires only if you type something in the
text box.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"RipperT" <rippert@nOsPaM.net> wrote in message
news:%23nrxKLNyHHA.4300@TK2MSFTNGP04.phx.gbl...
> Hi, Allen,
> Thanks for the response. The validation rule you suggest is completely
> ignored, as are my other attempts at validation rules.There must be other
> code interfering. I have code that fires in the BeforeUpdate, AfterUpdate
> and NotInList events. I'm not sure of the order of events, but would they
> be interfering? Anything I type in the validation rule box in properties
> just goes unnoticed by Access. Everything else works.
>
> Also, the Sub DigitOnly and the call to it generated an error:
>
> Compile error:
> ByRef argument type mismatch
>
> The code for the call looks like this:
>
> Private Sub InmateId_KeyDown(KeyCode As Integer, Shift As Integer)
> Call DigitOnly(KeyAscii)
> End Sub
>
> I don't know if maybe the two builder generated arguments have something
> to do with it?
>
> Thanks again,
>
> Rip
>
> "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
> news:OwpFoJByHHA.140@TK2MSFTNGP02.phx.gbl...
>> You could set the Validation Rule of the combo to:
>> Is Null OR Not Like "*[!0-9]*"
>> More examples of validation rules:
>> http://allenbrowne.com/ValidationRule.html
>>
>> Another approach would be to set the combo's On KeyDown event property
>> to:
>> [Event Procedure]
>> Click the Build button beside that.
>> Access opens the code window.
>> Between the "Private Sub..." and "End Sub" lines, enter this line:
>> Call DigitOnly(KeyAscii)
>>
>> Now create a new module (Modules tab of Database window, and click New.)
>> In the new code window paste the procedure below.
>>
>> What it does is to destroy all keystrokes except digits and the backspace
>> character. Any other key is just ignored. (A side effect is that hotkeys
>> such as Alt+Z to jump to another field do not work while you are in the
>> combo.)
>>
>> Public Sub DigitOnly(KeyAscii As Integer)
>> On Error GoTo Err_DigitOnly
>> 'Purpose: Disallow any keystroke except 0 ~ 9, and backspace.
>> 'Usage: In a text box's KeyDown event procedure:
>> ' Call DigitOnly(KeyAscii)
>>
>> If KeyAscii < 48 Or KeyAscii > 57 Then
>> If KeyAscii <> vbKeyBack Then
>> KeyAscii = 0
>> End If
>> End If
>>
>> Exit_DigitOnly:
>> Exit Sub
>>
>> Err_DigitOnly:
>> Msgox Err.Description
>> Resume Exit_DigitOnly
>> End Sub
>>
>> "RipperT" <rippert@nOsPaM.net> wrote in message
>> news:%23ESW94AyHHA.4652@TK2MSFTNGP05.phx.gbl...
>>>I have a combobox that gets it's values from a field in a table. Limit to
>>>list and auto-expand are both set to true. The (desired) validation rule
>>>is that the entry must be a 6 digit number (String) and not contain any
>>>letters or special characters. If I use an input mask, it kills the auto
>>>fill-in behavior that I want by forcing the user to click at the exact
>>>left hand side of the text box portion of the combo box. Also, it fills
>>>in the first entire number it finds as soon as they type the first
>>>character, whereas I want Access to fill in the number as they enter it.
>>>Is there a way to write a validation rule that will check that the number
>>>is 6 characters in length and will make sure that they enter only
>>>numbers, no letters or special characters? I've written code that checks
>>>for length, but how do I check
>>> for numbers only?
|
|
0
|
|
|
|
Reply
|
Allen
|
7/18/2007 10:36:57 AM
|
|
On Jul 17, 2:32 am, "Allen Browne" <AllenBro...@SeeSig.Invalid> wrote:
> > The (desired) validation rule is
> > that the entry must be a 6 digit number (String) and not contain any
> > letters or special characters.
>
> You could set theValidationRule of the combo to:
> Is Null OR Not Like "*[!0-9]*"
This doesn't validate the number of characters. Consider using the
pattern:
'[0-9][0-9][0-9][0-9][0-9][0-9]'
which has the advantage of being ANSI Query Mode neutral, making it
most suitable for a field/record Validation Rule.
Jamie.
--
|
|
0
|
|
|
|
Reply
|
Jamie
|
7/20/2007 11:02:53 AM
|
|
|
4 Replies
231 Views
(page loaded in 0.822 seconds)
Similiar Articles: multiple validation rules in tables? - microsoft.public.access ...How many validation rules are allowed in a table and how to separate each of them? Moreover can this be used [lname]<>[fname]? Thanks ... Validation Rule: Nearest Quarter-Hour - microsoft.public.access ...Can I create a validation rule in a form (or table) for a time field, where I ... Assume ee is entering time value into B2, assign a Custom Data Validation Rule to ... Override Validation Rule - microsoft.public.access.forms ...Override Validation Rule - microsoft.public.access.forms ... How to: Create a Custom Validation Rule... custom Validation Rule, with the new properties, you will see the ... "The Pattern String is Invalid" - microsoft.public ...Custom validation rule - microsoft.public.access.formscoding ..... rule is that the entry must be a 6 digit number (String ... 17, 2:32 am, "Allen Browne" <AllenBro ... Set validation rule for many fields with vba? - microsoft.public ...I want to set validation rules for 60+ fields, which are ... SQL Server allow you to define custom datatypes, and then you can easily define a rule on the dataType ... String validation - microsoft.public.access.formsCustom validation rule - microsoft.public.access.formscoding ... The (desired) validation rule is that the entry must be a 6 digit number (String) and not contain any ... custom autonumber - microsoft.public.accessI have a table: InactID-AutoNumber PreceptorID-Number InactStart-Date/Time ... custom autonumber - microsoft.public.access Validation rule to prevent overlapping time ... From field not auto-filling - microsoft.public.outlook.general ...Custom validation rule - microsoft.public.access.formscoding ... If I use an input mask, it kills the auto fill-in behavior that I want by forcing ... Data Validation: Validate Specific Day of the Week? - microsoft ...Text Field Validation Rule for Date - microsoft.public.access ..... to ... I selected E1 In the Data | Validation dialog, I used Custom and entered =WEEKDAY(E1)=2 I ... How to Round Time in Access? - microsoft.public.accessValidation Rule: Nearest Quarter-Hour - microsoft.public.access ... custom autonumber - microsoft.public.access Validation Rule: Nearest Quarter-Hour - microsoft.public ... How to: Create a Custom Validation RuleYou can create your own validation rules. To do this, you derive your own rule class from a validation rule class. Validation rules derive from the ValidationRule ... How to: Create a Custom Validation RuleYou can create your own validation rules. To do this, you derive your own rule class from a validation rule class. Validation rules derive from the T:Microsoft ... Building WP7 Custom Validation Control - Custom Validation Rules ...by WindowsPhoneGeek. This is the last post from the "Building WP7 Custom Validation Control" series of articles in which I talk about how to implement a fully ... Using Custom Validation Rules in WPF « Developing For .NETAnyone who has ever developed data driven applications of any sort has had to deal with validation. Let’s face it, users make mistakes, even if they are developers! Writing custom validation rules - cakebakerSometimes the built-in validation rules are not flexible enough for your specific validation needs, and so you have to write your own validation rules. 7/17/2012 3:12:46 PM
|