Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2006

Tip: Looking for answers? Try searching our database.

Len Validation Rule

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Igor G. - 28 Sep 2006 20:08 GMT
How to make validation rule for textbox; min. 8 and max. 10 characters?
I try with Len function but not work...
Len([Text0])<8 And Len([Text0])>10

Thanks!
ruralguy - 28 Sep 2006 21:19 GMT
Hi Igor,
You didn't say what event you are using to do the validation.  Your code
would need to be OR rather than AND and if you are using the BeforeUpdate
event to validate (which is the usual event for validation then you will need
to use the Text property rather than the default .Value property:
If Len(Me.Text0.Text)<8 OR Len(Me.Text0.Text)>10 Then
  MsgBox "At least 8 and no more than 10 characters"
  Cancel = True
End If

>How to make validation rule for textbox; min. 8 and max. 10 characters?
>I try with Len function but not work...
>Len([Text0])<8 And Len([Text0])>10
>
>Thanks!

Signature

HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Igor G. - 29 Sep 2006 09:00 GMT
I use Validation Rule in form TextBox property.
Error message is in the Validation Text property.

> Hi Igor,
> You didn't say what event you are using to do the validation.  Your code
[quoted text clipped - 11 lines]
> >
> >Thanks!
ruralguy - 29 Sep 2006 15:54 GMT
Igor, it sounds like you are using the validation elements of the table and
not in the form.  I would recommend *not* using the table validation and
instead use what I posted in the BeforeUpdate event of the TextBox control
for this field.

>I use Validation Rule in form TextBox property.
>Error message is in the Validation Text property.
[quoted text clipped - 4 lines]
>> >
>> >Thanks!

Signature

HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Tim Ferguson - 29 Sep 2006 20:41 GMT
> Igor, it sounds like you are using the validation elements of the
> table and not in the form.  I would recommend *not* using the table
> validation and instead use what I posted in the BeforeUpdate event of
> the TextBox control for this field.

Why do you say this? There are many ways of updating or filling fields in
tables: using a form, using a query, typing into the table datasheet, SQL
embedded in VBA, merging from Excel or Word... even CorelDraw has a VBA
module that can update a database. If the data in the table are to be
protected, then it has to be at the DBEngine level; and that means a
field-level or table-level ValidationRule.

You are half-right, of course. No self-respecting user likes to see a DB
error message about field contents, and no self-respecting developer
should let an error like that get sent to the engine. Therefore,
intelligent handling of e.g. the BeforeUpdate event is required too.

But don't imagine that a bit of code in one form is going to maintain the
integrity of the real data on its own.

Best wishes

Tim F
John Spencer - 29 Sep 2006 12:39 GMT
You rule says that the entry must be 8 or less characters and at the same
time it must be 10 or more characters.  That is impossible.

If you want the length to be 8, 9, or 10 characters then the rule would be
Len([Text0])>=8 Or Len([Text0])<=10

If you want the length to be 1 to 7 characters or 11 to any number of
characters the rule would be
    Not(Len([Text0])>=8 Or Len([Text0])<=10)

> How to make validation rule for textbox; min. 8 and max. 10 characters?
> I try with Len function but not work...
> Len([Text0])<8 And Len([Text0])>10
>
> Thanks!
Tom Lake - 29 Sep 2006 12:49 GMT
> You rule says that the entry must be 8 or less characters and at the same
> time it must be 10 or more characters.  That is impossible.
>
> If you want the length to be 8, 9, or 10 characters then the rule would be
> Len([Text0])>=8 Or Len([Text0])<=10

Shouldn't that be an And rather than Or?  With Or,  a length of 2 would be
legal
since Len([Text0])<= 10 is true.

Tom Lake
John Spencer - 29 Sep 2006 14:18 GMT
Yes,  it should be AND not OR.  Too much coffee or too little coffee on my
part.

I had changed my mind on which way to test this and forgot to make changes
to what I had already typed.
Thanks for the catch.

>> You rule says that the entry must be 8 or less characters and at the same
>> time it must be 10 or more characters.  That is impossible.
[quoted text clipped - 8 lines]
>
> Tom Lake
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.