I am sorry for not replying earlier but had to leave the office for medical reasons.
Nothing needs to happen if it is false. I am using the "1" to mark the records so that I can perform summary calculations later.
Main Topics
Browse All TopicsI have a Union query that will not return duplicate records. If I run each select statement by itsel,f I get a record with a que_rpt_Schedule_s1.ID (first field) of 11605. In the union query I only get one record with 11605. Each select statement is using a join on a different field in the second table.
Any help would be appreciated
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I do not believe the false condition of a IIF() function is optional, but then Jet, the db engine in Access is sometimes too lazy about raising flags . If you do not want anything to happen, try inserting ,Null after each of the four ,1's in your query as in:
IIf([startdate] Between [startofweek] And [endofweek],1,Null)
Does that change anything?
I still get the same results. I also tried using 0 instead of Null.
The funny thing is that the select staments work by themselves. They just don't work as part of the union. Only the first select works regardless of which statement I put first.
I'm wondering if this has somnething to do with the way that I built the source tables.
That is good to know about the db engine not always raising errors.
I actually lay out my sql the same way but Acess seems to condense the code whenever I leave the query. I am not seing anything in your code different then mine. I did paste your code and I am still having the same issue.
Thanks for you help but I think that I will try to create a work around. The functionality is not worth spending too much more time on.
Nico5038,
I had tried to execute the union the way you suggested and I got the same results. This is the strangest problem. I have used the union functionality many times and I have not had this problem. I am thinking that it must have something to do with the relationships between the tables.
Thanks for the suggestion
The False isn't needed, but there's another flaw, the intermediate ";" after the first query, hragape try:
SELECT que_rpt_Schedule_s1.ID, ref_dates_week.ID, ref_dates_week.StartofWeek
IIf([startdate] Between [startofweek] And [endofweek],1) AS S1_IN,
que_rpt_Schedule_s1.s2Star
FROM ref_dates_week
LEFT JOIN que_rpt_Schedule_s1 ON ref_dates_week.ID = que_rpt_Schedule_s1.Startw
UNION ALL
SELECT que_rpt_Schedule_s1.ID, ref_dates_week.ID, ref_dates_week.StartofWeek
IIf([startdate] Between [startofweek] And [endofweek],1) AS S1_IN,
que_rpt_Schedule_s1.s2Star
FROM ref_dates_week
LEFT JOIN que_rpt_Schedule_s1 ON ref_dates_week.ID = que_rpt_Schedule_s1.S2_Sta
Nic;o)
Hmm, my test query works flawlessly with the UNION ALL with and without the intermediate ";" , so I assume it's something in the data when the previous tip doesn't work.
Can you create a sample .accdb with (part of) the tables and the query and attach that to the comment so GRayL and I can have a look?
Nic;o)
As an old veteran expert you should know it's always in the details Ray <LOL>
Still puzzled why the ";" doesn't interfere for me in the accdb database, from the "old" .mdb databases I know you get a message when there's something behind the final ";".
OK, glad it's now working hragape, success with your application !
Nic;o)
Business Accounts
Answer for Membership
by: GRayLPosted on 2008-06-22 at 13:32:26ID: 21842102
In the iif statements in both SELECT statements, you have not include the FALSE criteria, ie. what is supposed to happen if the [startdte] is not between the two test dates?