Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Functions not working in Access 2007 Queries

24 views
Skip to first unread message

Scrimmo

unread,
Aug 10, 2009, 10:28:01 AM8/10/09
to
Although queries using columns from tables/queries are working fine, queries
that use functions fail.

For example, this query:

SELECT Schedule.S_WEEK, nz([S_LWEEK],0) AS Expr1
FROM Schedule;

fails with the following error message:

Compile error . in query expression 'nz([S_LWEEK],0'.

This appears to be happening with any function, and whether I use the
expression builder (which puts the table name in as well).

This is the first time I've come across this - I've been using Access for
years.

Any ideas, anyone?

Oh, by the way, S_LWEEK is a Long Integer, but I'm getting this on Integers
as well.

The database is in a trusted location, and I've even turned Sandbox off for
Access, although the pages that told me how to do that didn't mention NZ in
either the "Blocked" or "Works OK" list.

Thanks

John Spencer

unread,
Aug 10, 2009, 10:59:00 AM8/10/09
to
Have you checked the library references to make sure there is no problem with
the references?

Here are MVP Doug Steele's instructions for how to do it:

*** Quote ***

Any time functions that previously worked suddenly don't, the first thing to
suspect is a references problem.

This can be caused by differences in either the location or file version of
certain files between the machine where the application was developed, and
where it's being run (or the file missing completely from the target machine).
Such differences are common when new software is installed.

On the machine(s) where it's not working, open any code module (or open the
Debug Window, using Ctrl-G, provided you haven't selected the "keep debug
window on top" option). Select Tools | References from the menu bar. Examine
all of the selected references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you just
unselected (you can tell by doing a Compile All Modules), go back in and
reselect them.

If none have "MISSING:", select an additional reference at random, back out of
the dialog, then go back in and unselect the reference you just added. If that
doesn't solve the problem, try to unselect as many of the selected references
as you can (Access may not let you unselect them all), back out of the dialog,
then go back in and reselect the references you just unselected. (NOTE: write
down what the references are before you delete them, because they'll be in a
different order when you go back in)

For far more than you could ever want to know about this problem, check out
http://www.accessmvp.com/djsteele/AccessReferenceErrors.html

Just so you know: the problem will occur even if the library that contains the
specific function that's failing doesn't have a problem.

**** End Quote ****

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Scrimmo

unread,
Aug 10, 2009, 11:09:03 AM8/10/09
to
Yeah, thanks John.

They all look OK - no errors or "Missings".

Just to confirm, this is not in a code module - this is creating and running
(trying to run) a Query interactively.

John Spencer

unread,
Aug 10, 2009, 1:13:07 PM8/10/09
to
Yes, but NZ is a VBA function. If the references were messed up, then the
function can fail even if the reference that is messed up is not the VBA library.

I would double-check and make sure the database is in a trusted location.

Your sample query could be rewritten with IIF, but that doesn't explain why
all the functions are failing.

Bob Barrows

unread,
Aug 10, 2009, 1:58:57 PM8/10/09
to
NZ is blocked. I've tried turning Sandbox mode off, but it has not had
any effect on my ability to use Access-defined functions like NZ.
Are you running this query via ADO? If so, you won't be able to use NZ,
since it will be blocked even if you are running the code from an Access
VBA module. ADO is considered "external".

--
HTH,
Bob Barrows


Bob Barrows

unread,
Aug 10, 2009, 2:01:34 PM8/10/09
to
Scrimmo wrote:
> Yeah, thanks John.
>
> They all look OK - no errors or "Missings".
>
> Just to confirm, this is not in a code module - this is creating and
> running (trying to run) a Query interactively.
>
Oops - disregard my previous reply.
It certainly sounds like a References problem, even though you say you
have eliminated that. Why not go through all the references, unclicking
them, then opening the dialog again to recheck them.
--
HTH,
Bob Barrows


Scrimmo

unread,
Aug 11, 2009, 3:57:01 AM8/11/09
to
Thanks for all the suggestions - I've had another look at the references and
all seems OK. I have a function that uses NZ and that works just fine.

I just created a new database, imported everything from the old one, and
tried to create a new query with the same results.

Just to reiterate, this problem is with a Query designed and Viewed
interactively - this is NOT a query in a module.

Richard

Scrimmo

unread,
Aug 11, 2009, 11:10:01 AM8/11/09
to
OK, I have no explanation for this, but it is now working again.

I love stuff like this.

Bob Barrows

unread,
Aug 11, 2009, 11:13:45 AM8/11/09
to
Scrimmo wrote:
>>> For example, this query:
>>>
>>> SELECT Schedule.S_WEEK, nz([S_LWEEK],0) AS Expr1
>>> FROM Schedule;
>>>
>>> fails with the following error message:
>>>
>>> Compile error . in query expression 'nz([S_LWEEK],0'.
>>>

Was that the exact sql from the query builder's SQL View?

You said that other functions fail as well ... are all the functions
that fail VBA functions? Do intrinsic Jet functions like Avg or Max
work? How about non-Access-defined functions like CStr, etc.? How about
user-defined functions?
--
HTH,
Bob Barrows


Scrimmo

unread,
Aug 11, 2009, 11:39:01 AM8/11/09
to
NZ failed and now works
A function I threw together that used (and emulated) nz failed and now works
- it always did work in the Immediate window.
Cstr failed and now works.

Richard

0 new messages