Avatar of Jon Bredensteiner
Jon BredensteinerFlag for United States of America

asked on 

Access to Excel Query Error

Good morning all,
      I am trying to import data into Excel from an Access query.  When I try to add the query via the Microsoft Query manager in Excel, I receive the following error “Undefined function ‘NZ’ in expression”.  I know what is causing the error, but I don’t know why.
      I built the query in Access, and it joins multiple tables, and the problem was that one of the tables, which is being pulled from SQL Server via an ODBC hook, has the employees’ ID listed as text instead of a number, so when I joined the tables I used the below syntax to change the data from text to an integer; you can see my other posting relating to this at https://www.experts-exchange.com/questions/22136592/Join-tables-using-one-integer-and-one-string-as-an-integer.html

My join statement:
 tbl_OrgMaster_2.BemsID = CLng(NZ(ENGPI_dbo_tbl_process_owner.Focal_Bems,0))

What’s weird is that I am not even trying to pull data directly from the query that contains the above join syntax “qry_DocumentMaster”, as I am pulling from another query “qryDIMaster” that pulls from the aforementioned query.

So, my question is, can I work around this, or will I have to do something like make an update table query, and then run it every time I want new data to be available in Excel?

Thanks in advance for your help, Jon
Microsoft ExcelSQL

Avatar of undefined
Last Comment
Jon Bredensteiner
ASKER CERTIFIED SOLUTION
Avatar of LoNeRaVeR9
LoNeRaVeR9
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Rory Archibald
Jon,
I think that if you replace your NZ with the longwinded iif(isnull(...),0,...) version, it should work in MSQuery.
Regards,
Rory
Avatar of Jon Bredensteiner

ASKER

    I'm sorry, but I am not sure where to put the IIF statement.  Thanks again for your help.  Here is the query; I shortened it a lot to make it easier to read:

SELECT ENGPI_dbo_tbl_process_owner.ID, IIf(IsNull(tbl_OrgMaster_2.BemsID),0,tbl_OrgMaster_2.BemsID) AS ProcessFocalBems, IIf(IsNull(tbl_OrgMaster_2.Name),"Unknown",tbl_OrgMaster_2.Name) AS ProcessFocal
FROM OrgBuilder_OrgMaster AS tbl_OrgMaster_2 RIGHT JOIN ENGPI_dbo_tbl_process_owner ON tbl_OrgMaster_2.BemsID = CLng(NZ(ENGPI_dbo_tbl_process_owner.Focal_Bems,0));


SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Jon Bredensteiner

ASKER

Oh, ok, I didn't know you could do that.  I just tried it, and it worked.  Thanks for the help.
Avatar of Jon Bredensteiner

ASKER

Can you tell me what the NZ portion of my old statement is actually used for or what it does?  Thanks,
Nz is an Access function that returns the value of a field, unless it is Null, in which case it returns a specified value. So:
Nz([Field1],0)
will return 0 if Field1 is null, otherwise it returns Field1. It is just a shorter version of:
=iif(IsNull([Field1]),0,[Field1])
Regards,
Rory
Avatar of Jon Bredensteiner

ASKER

So why wouldn't Nz work instead of using the =iif(IsNull([Field1]),0,[Field1]) statement?  Thanks,
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo