If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Can't use Nz in validation rule?!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-12, 12:25
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
Can't use Nz in validation rule?!

Using Access 2007, trying to create a table/row-level validation rule on an existing table that already has data. Here's my rule:

Code:
Nz([start_date], #12/31/9999#) <= Nz([end_date], #12/31/9999#)
Here's the error I get when Access tries to validate existing data against the new rule:
Quote:
Unknown function 'Nz' in validation expression or default value on 'mytable'
So ... is Access really telling me it doesn't recognize one of it's own built-in functions, even though the function is included in the list of available built-in functions in the expression builder window?

Please, someone tell me I'm doing something stupid or missing something obvious here.
Reply With Quote
  #2 (permalink)  
Old 01-17-12, 12:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
maybe it doesn't work on date/time columns??

try IIf(IsNull([datecol]),#12/31/9999#,[datecol])
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-17-12, 12:54
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
I'm not sure that Nz() is accessible from the Jet engine. Nz() (and also EVal() and the domain functions: DLookUp(), DCount(), etc.) is a member of the Microsoft Access xx.x Object Library (Access.Application) , not of the VBA library.

From Allen Browne (Microsoft Access tips: Validation Rules)
Quote:
You cannot use a validation rule where you want to call user-defined functions, or VBA functions beyond the ones in JET such as IIf() and Date().
__________________
Have a nice day!
Reply With Quote
  #4 (permalink)  
Old 01-17-12, 18:13
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
Quote:
Originally Posted by r937 View Post
try IIf(IsNull([datecol]),#12/31/9999#,[datecol])
Yup, that worked. Many thanks.

Quote:
Originally Posted by Sinndho View Post
I'm not sure that Nz() is accessible from the Jet engine.
Well, except you can use Nz() in queries:
Code:
select *
from mytable
where nz(start_date, #12/31/9999#) > nz(end_date, #12/31/9999#)
Not that you're wrong, but it seems pretty arbitrary that a built-in function that works with plain SQL queries is suddenly not recognized when trying to implement table constraints.

Another fruit basket to Micros**t for wasting my time with their broken software. They must be piling up on their desks by now....

P.S., thanks for the link; very helpful.

Last edited by futurity; 01-17-12 at 18:22.
Reply With Quote
  #5 (permalink)  
Old 01-17-12, 20:57
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
Quote:
Originally Posted by futurity View Post

...it seems pretty arbitrary that a built-in function that works with plain SQL queries is suddenly not recognized when trying to implement table constraints.
Not really, when you think about it! The entire point of Queries is facilitate the manipulation of data, so having data-manipulating Functions work within them makes perfect sense. The entire point of Tables is to store data...period! Tables are not meant to be used for data manipulation.

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On