Re: Custom Validation Rules

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Allen Browne (AllenBrowne_at_SeeSig.Invalid)
Date: 01/19/05


Date: Wed, 19 Jan 2005 21:32:51 +0800

Yes, you would not normally modify the ValidationRule property of a table
field once the database is in use, though you might need to create or clear
a rule as part of a version update on a database that is already installed.

If you have a Validation Rule in place in the field of the table or in the
table itself, you don't need any code. If the validation is too complex to
use the rule in the table, or if you want to give the user the chance to
override it and make the entry anyway, then it makes sense to use the form
events for this. Use the BeforeUpdate event of the control to validate one
field (e.g. to make sure it is in range), or the BeforeUpdate event of the
form to validate the record (e.g. to compare values between fields, or to
ensure that an entry was made in a field.)

Again, once you have this code in place, you would not normally need to
change the code, unless you need it for a version update.

Hope that's useful

-- 
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.
"TonyB" <tonyb@kerrisway.freeserve.co.uk> wrote in message
news:uVRMzPi$EHA.3336@TK2MSFTNGP11.phx.gbl...
> Hi Allen,
> Thanks for the reply. I didn't explain myself clearly. I was looking for a
> general method of attaching some vba code to the field in a record so that
> when a new record is entered that this code can be run to check the data 
> for
> that field is OK Basically I am trying to customize the validation rules 
> you
> get in table design view.
> Since I posted I have been searching for info about this, and I think I 
> have
> concluded this is probably not possible in a table, and that this should 
> be
> done in the form used to enter the data into the table, rather than in the
> table. Would you agree ?
>
> Thanks
> Tony
>
>
> "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
> news:eipMJpg$EHA.2032@tk2msftngp13.phx.gbl...
>> To programatically set the Validation Rule property for a field named
> Email
>> in a table named Table1, try something like this:
>>
>> Currentdb.TableDefs("Table1").Fields("Fee").ValidationRule = _
>>     "Is Null Or ((Like ""*?@?*.?*"") And (Not Like ""*[ ,;]*""))" 


Relevant Pages

  • Re: Validation of text
    ... If you are saying that designing effective database constraints is hard ... should) write form-level validation *and* database level ... you used the Validation Rule property of the fields in your table, ...
    (microsoft.public.access.forms)
  • Re: Validation Rule for field using table property
    ... FieldA and FieldB in combination: ... validation rule: ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Validation Rule for field using table property
    ... FieldA and FieldB in combination: ... validation rule: ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Validation Rule for field using table property
    ... FieldA and FieldB in combination: ... validation rule: ...
    (microsoft.public.access.tablesdbdesign)
  • Re: querry for sending email
    ... example, on Windows 95 with Access 2, you can define a table validation ... The arguments you pass to Shell can involve fields of the actual record ... You CANNOT use SHELL in a secure db for a table validation rule. ... You can change a table validation rule from the User Interface for table ...
    (microsoft.public.access.queries)