Solved

Access Query error code

Posted on 2013-11-15
18
224 Views
Last Modified: 2014-01-03
I created a small DB to program, test and then import into an existing DB.  The below query works fine in a small DB, but gives an error when imported into existing DB. See attached

Here is the query syntax that works fine in small DB  
StatusNew: IIf([FACaseNo]+[TANFCaseNo]+[FosterChild]<>0,"F",IIf([NonNeedy] Is Not Null,"N",Nz(DLookUp("[IncomeType]","IEG"," [IEG]![HHSize]=" & [IEChild]![HHSize] & " AND [Frequency]='" & [IEChild]![HHFrequency] & "' AND  [IncomeThreshold] >=" & [IEChild]![HHInc ome] & ""),"N")))

Can you tell me why this is occurring?Error message when running queryI created a small DB to program, test and then import into an existing DB.  The below query works fine in a small DB, but gives an error when imported into existing DB. See attached

Here is the query syntax that works fine in small DB  
StatusNew: IIf([FACaseNo]+[TANFCaseNo]+[FosterChild]<>0,"F",IIf([NonNeedy] Is Not Null,"N",Nz(DLookUp("[IncomeType]","IEG"," [IEG]![HHSize]=" & [IEChild]![HHSize] & " AND [Frequency]='" & [IEChild]![HHFrequency] & "' AND  [IncomeThreshold] >=" & [IEChild]![HHInc ome] & ""),"N")))

Can you tell me why this is occurring?
0
Comment
Question by:softsupport
18 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
perhaps a null value in field

[IEChild]![HHFrequency]
0
 

Author Comment

by:softsupport
Comment Utility
Do you mean like this?  Nz([IEChild]![HHFrequency])
That did not work.  Did I do that correctly?
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
what is the field "[Frequency]" data type ?
0
 

Author Comment

by:softsupport
Comment Utility
text
0
 
LVL 26

Expert Comment

by:jerryb30
Comment Utility
Can you post a sample db? Sanitized records? No records if this is not possible.
0
 

Author Comment

by:softsupport
Comment Utility
Do you mean post a sample of the smaller DB?  As stated, the smaller DB works fine, it is when imported into the existing larger DB, I receive errors.  Would this import cause an issue?  Larger DB is just that.... large and not able to post.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
there could be a corrupted record in the big db that is causing the error.

can you post a sample db with the table "IEChild"
0
 

Author Comment

by:softsupport
Comment Utility
I will post.  Should not be corrpt record as it is not connected to any tables and has no data.
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
From the error message you posted, it looks like you have nulls in BOTH HHFrequency and HHIncome.  You shouldn't need NZ around HHFrequency (the single quote text delimiters are automatically handling nulls), but HHIncome might be a problem.

Try this:

StatusNew: IIf([FACaseNo]+[TANFCaseNo]+[FosterChild]<>0,"F",IIf([NonNeedy] Is Not Null,"N",Nz(DLookUp("[IncomeType]","IEG"," [IEG]![HHSize]=" & [IEChild]![HHSize] & " AND [Frequency]='" & [IEChild]![HHFrequency] & "' AND  [IncomeThreshold] >=" & NZ([IEChild]![HHInc ome], 0),"N")))

Open in new window


Also, look at the field name [IEChild]![HHInc ome].  You have a space in Income that looks out of place.  Should the field name be [IEChild]![HHIncome] (without the space)?

StatusNew: IIf([FACaseNo]+[TANFCaseNo]+[FosterChild]<>0,"F",IIf([NonNeedy] Is Not Null,"N",Nz(DLookUp("[IncomeType]","IEG"," [IEG]![HHSize]=" & [IEChild]![HHSize] & " AND [Frequency]='" & [IEChild]![HHFrequency] & "' AND  [IncomeThreshold] >=" & NZ([IEChild]![HHIncome], 0),"N")))

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:softsupport
Comment Utility
When I run the IEChild Form is where the error occurs in the existing database.  The IEstatus query is generating the error. Syntax error above occurs sporadically as stand alone DB, but occurs all the time when I import into an existing database.
App.accdb
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
try to find the record that is raising the error, it could be a corrupted record
from any of the 4 tables in query IEStatus.

you can run this codes (place in a regular module) and probably catch the corrupted record..

change "NameOfTable" with the 4 tables in the query for each run.


sub checkRecords()
on error goto rs_error
dim rs as dao.recordset, j as long, k as integer
set rs=currentdb.openrecordset("NameOfTable")

if rs.eof then
   msgbox "No records"  
   exit sub
end if

rs.movefirst
j=1
do until rs.eof
     for k=0 to rs.fields.count-1
        debug.print j & " - " & rs(k).name  & " - " & rs(k)
     next
j=j+1
rs.movenext
loop

rs.close

 rs_error:
          msgbox err.number & vbcrlf & err.description & vbcrlf & "Record No :" & j

end sub
0
 

Author Comment

by:softsupport
Comment Utility
Ran module above as instructed, in query where error occurs....  No errors or corrupt data found in any tables. UGH!  Was hoping this would find something....

In FrmIEChild, when I enter HHSize, HIncome, Frequency and click on button "Qualify",  I now receiving a compile error.  Attached...Compile error, and this message follows.Message after compile error
Can this be the culprit?

After I exit the error in VBA, and press button "Qualify" again, I receive the following message listed above.  Original Error
Would the first error trigger the last one?
0
 

Author Comment

by:softsupport
Comment Utility
Any suggestions???!!!
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
Run a query against [IEChild]![HHFrequency] and see if it has any quotes or apostrophe's in it.

In a new query, define two columns:

Expr1: InStr([HHFrequency],"'")
Expr2: InStr([HHFrequency],"""")

 and check for a value of > 0

Jim.
0
 
LVL 84
Comment Utility
I don't know that you'll ever troubleshoot something like this, with the queries in the state they are. You've got DLookups in aliased columns, and that's just a recipe for disaster. For example, in the IEStatus query you have this:

Status: Nz(DLookUp("[IncomeType]","IEG"," [IEG]![HHSize]=" & [IEChild]![HHSize] & " AND [Frequency]='" & [IEChild]![HHFrequency] & "' AND  [IncomeThreshold] >=" & [IEChild]![HHIncome] & ""),"N")

You really should add in the IEG table a second time and join it to IEChild table, or create a query that provides that data and add that query to the IEStatus query, something like:

SELECT IEChild.ChildIE, IEChild.HHIncome, IEG.IncomeType
FROM IEG INNER JOIN IEChild ON (IEG.Frequency = IEChild.HHFrequency) AND (IEG.HHSize = IEChild.HHSize)
WHERE (((IEChild.HHIncome)>[IEChild].[HHIncome]));

Save that query as "qIEChildIncomeType", and then add that query to the IEStatus query, and join it on CqIEChildIncomeType.ChildID=IEChild.ChildIE. This should give you the IncomeType for each Child in that initial query.

I'm not sure exactly what the database is used for, but if you could give us some insight into that we might be able to suggest a more efficient design. Anytime you see queries that must rely on IIFs, DLookups, DCounts, etc the underlying design is always suspect.

=======

Regarding your errors:

The "User Defined Type" error means either (a) you do not have a reference to the DAO library or (b) you DO have a reference, but there is trouble with the database. I downloaded the db you attached on 11-19, and the reference is okay in that one, and I don't get any compile errors. That doesn't mean your copy is okay on your machine, however, so first thing to do is perform maintenance:

First, make a backup.

Now do this:

1. Compact the database
2. Compile the database - from the VBA Editor click Debug - Compile. Fix any errors, and continue doing this until the Compile menuitem is disabled.
3. Compact again

Now Decompile it - Build a Shortcut with this as the Target:

"full path to msaccess.exe" "full path to your db" /decompile

Run this shortcut, then do the 3 steps above again.

Also, be sure that your machine is fully updated regarding Office and Windows.
0
 

Author Comment

by:softsupport
Comment Utility
Thank you for your input and suggestions.  The DLookup were previous suggestions from other experts from EE.  The purpose of the DB is to enter a household size, income and frequency to establish where the family lies within the IEG table. The family may have multiple incomes and frequencies therefore the income is annualized for determination.  If they do not qualify within the table then they qualify as N.  The data is entered on the IEChild Table and determined by pressing Qualify.  Hope this gives a little more insight on purpose.

There is a reference to the DAO library in the HHI subform... I will perform maintenance you suggested.
0
 

Author Comment

by:softsupport
Comment Utility
I have performed the maintenance as you suggested without any errors.  When I import all items into a larger database.... I get the DAO library error.  The imported DB was designed in 2007 while the larger database in 2003. Can that be the issue and if so how do I correct?
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
<The imported DB was designed in 2007 while the larger database in 2003.>

wished you mentioned this at your original post..

from the larger db
check your references
from VBA window

Tools > references
look for reference prefix with "MISSING:"

uncheck, then locate the available version of the reference

click OK

Do a DEBUG > Compile
make sure there are no more error raised
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now