Solved

Access Prompts when I use Criteria

Posted on 2011-09-15
14
237 Views
Last Modified: 2012-05-12
When I use the query criteria selection  >0      Access prompts for NewWe and then prompts for PASTWE.  When I don't use criteria I get the data fine but I don't want the data that is zero.

Field: WE13: IIf(CDate([NewWe])<=DateAdd("ww",13,CDate([PASTWE])),([NewWe]),0)


Criteria: >0
0
Comment
Question by:CompTech810
  • 5
  • 3
  • 2
  • +4
14 Comments
 
LVL 15

Expert Comment

by:Simon Ball
ID: 36545773
are those expressions - the newwe and pastwe - if so, i think having the >0 criteria causes the clause to be evaluated before they have been created....

add a new column for the criteria and see if that helps
0
 
LVL 15

Accepted Solution

by:
Simon Ball earned 125 total points
ID: 36545779
actually, i think when i encountered this problem, i ended up savign query1... and adding a 2d query, with select * from query 1 in it, and then putting the criteria and there for that column, so that it forces the expressions to be created before the criteria is apllied...
0
 
LVL 2

Author Comment

by:CompTech810
ID: 36545782
I did that.  I added Expr1: [WE13]  with the criteria of >0 and then it prompted for WE13.

0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 2

Author Comment

by:CompTech810
ID: 36545794
Hmmm....  I'll have to try that.  
0
 
LVL 75
ID: 36545801
Can you post the full SQL for the query?

mx
0
 
LVL 2

Author Comment

by:CompTech810
ID: 36545826
Sudonim:  That has appeared to work, awesome.  I'm going to leave this open until I finish testing.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36545868
You don't actually need two queries.  Sudonim's logic is sound, but the problem can also be handled by using the experssion instead of it's alias in the WHERE clause.

In other words, the SQL view would look like this:

SELECT field1, field2, DateAdd("ww",13,CDate([PASTWE])),([NewWe]),0) as [WE13]
FROM somewhere
WHERE DateAdd("ww",13,CDate([PASTWE])),([NewWe]),0) > 0


You would likewise use the expression, not the alias in an Order  By clause, I believe.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36545870
You can almost certainly be achieved in a single query.  Please post the SQL statement, as MX requested.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36545889
I missed part of the expression in the above... it should be IIf(CDate([NewWe])<=DateAdd("ww",13,CDate([PASTWE])),([NewWe]),0)  in both places, but you get the idea.


0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 36548101
aah yes, good call mbizup

you will need to replace both the expressions source code in the where clause.

If its not a big query, i'd stick with having two...
0
 
LVL 2

Author Comment

by:CompTech810
ID: 36548591
Here is the SQL statement:


SELECT Administrators_SOD_1_BaseData.Item_Wo_Gl, Administrators_SOD_1_BaseData.Cust_Name, Administrators_SOD_1_BaseData.Description, Administrators_SOD_1_Del_Date_Data.Req_Del_Dt, Administrators_SOD_1_BaseData.Qty_On_Hand, Administrators_SOD_1_Del_Date_Data.Bal_Qty, Administrators_SOD_1_Del_Date_Data.Bal_Ext_Price, Administrators_SOD_1_Del_Date_Data.ID, Administrators_SOD_1_Del_Date_Data.Prod_Del_Date, Administrators_SOD_1_Del_Date_Data.Prod_Date_Note, Date()-Weekday(Date())+1 AS PASTWE, CDate(IIf(Weekday(Nz([Prod_Del_Date],[Req_Del_Dt]))=1,(Nz([Prod_Del_Date],[Req_Del_Dt])),(8-Weekday(Nz([Prod_Del_Date],[Req_Del_Dt])))+(Nz([Prod_Del_Date],[Req_Del_Dt])))) AS WEDATE, IIf([WEDATE]<[PASTWE] And [Prod_Del_Date] Is Null,"1/1/2000",[WEDATE]) AS NewWE, IIf(CDate([NewWe])<=DateAdd("ww",13,CDate([PASTWE])),([NewWe]),0) AS WE13
FROM Administrators_SOD_1_BaseData INNER JOIN Administrators_SOD_1_Del_Date_Data ON Administrators_SOD_1_BaseData.ID = Administrators_SOD_1_Del_Date_Data.ID
WHERE (((Administrators_SOD_1_Del_Date_Data.Bal_Qty)>0))
ORDER BY Administrators_SOD_1_BaseData.Item_Wo_Gl;
0
 
LVL 2

Expert Comment

by:mansooralia_yahoo
ID: 36553878
enclose the fields in square braces [ ]
0
 
LVL 1

Expert Comment

by:smartcheater
ID: 36554683
Use WHERE instead of IF.

and

Date type data comparision are made in text format by default not as number format. So you will not get a required output. You will have to write a self procedure for comprision.
0
 
LVL 2

Author Closing Comment

by:CompTech810
ID: 36573910
I elected to pick this solution because of timing and did not have a chance to try the rest of the solutions provided.  Thanks everyone for their solutions.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

821 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