473,385 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Form shows incorrect results from Union Query

Hi Everyone, I'm back for some more expert help. Here's what I am
doing and what I tried.

My database has entries with Contract Names and Expiry Dates, among
other fields. I have a form designed to show the expiring contracts.
To do this I use a straight forward query in my form's ON LOAD code

strwhere = "[Expiry_Date] BETWEEN #" & Now() & "# AND #" &
DateAdd("m", 6, Now()) & "#"
Set MyQueryDef = MyDatabase.CreateQueryDef("qryMattersQuery", "SELECT
* FROM Matters " & (" WHERE " & strwhere & " ORDER BY
[Expiry_Date];"))

This looks 6 months into the future and puts the expiring contract
info into a query. I use this query as the record source for a for
with conditional formatting to color code by time interval.

When the form's Record Source is set to the query "qryMattersQuery" =,
everything works.

I then created another query to check and alter the expiry Date for
contract in the past (since the database was last accessed). I use
analogous coding as shown above and create a query called
"qryExpiringList". When I set that as the Record Source for my form,
it works fine.

What doesn't work right is:

I want to show all of the results at the same time on the form. So, I
created a Union query with the following line of code:

Set MyQueryDef = MyDatabase.CreateQueryDef("qryUnionQuery",
"SELECT * FROM qryExpiringList UNION SELECT * FROM qryMattersQuery
ORDER BY [Expiry_Date];")

The query results in tabular format are correct, but when I use the
query as the record source for my form, I don't always get the correct
results. I frequently see additional entries listed, seemingly
leftover from previous queries.

I have even added code to delete the previous queries before they are
created:

If ObjectExists("Queries", "qryUnionQuery") = True Then
MyDatabase.QueryDefs.Delete "qryUnionQuery"
MyDatabase.QueryDefs.Refresh
End If

but I still get the leftover record on the form, but NOT in the
tabular display of the UnionQuery results. The tabular display is
always what I expect to see. Where are the old results being stored?

I'm stumped. Thanks in advance for you help.

- Bernie

May 10 '07 #1
1 2654
Hi,
I don't have the answer but here are two things you might want to try
or concider

- you know that there are two types of union queries, right? 'Union'
and 'Union All'

- maybe its not the querydef that needs refreshing, it might be that
the form needs either refreshing or requerying after you set the query
to the new querydef something like; Me.Form.ReQuery or Me.Form.Refresh

bobh.

On May 10, 3:09 pm, bgreens...@gmail.com wrote:
Hi Everyone, I'm back for some more expert help. Here's what I am
doing and what I tried.

My database has entries with Contract Names and Expiry Dates, among
other fields. I have a form designed to show the expiring contracts.
To do this I use a straight forward query in my form's ON LOAD code

strwhere = "[Expiry_Date] BETWEEN #" & Now() & "# AND #" &
DateAdd("m", 6, Now()) & "#"
Set MyQueryDef = MyDatabase.CreateQueryDef("qryMattersQuery", "SELECT
* FROM Matters " & (" WHERE " & strwhere & " ORDER BY
[Expiry_Date];"))

This looks 6 months into the future and puts the expiring contract
info into a query. I use this query as the record source for a for
with conditional formatting to color code by time interval.

When the form's Record Source is set to the query "qryMattersQuery" =,
everything works.

I then created another query to check and alter the expiry Date for
contract in the past (since the database was last accessed). I use
analogous coding as shown above and create a query called
"qryExpiringList". When I set that as the Record Source for my form,
it works fine.

What doesn't work right is:

I want to show all of the results at the same time on the form. So, I
created a Union query with the following line of code:

Set MyQueryDef = MyDatabase.CreateQueryDef("qryUnionQuery",
"SELECT * FROM qryExpiringList UNION SELECT * FROM qryMattersQuery
ORDER BY [Expiry_Date];")

The query results in tabular format are correct, but when I use the
query as the record source for my form, I don't always get the correct
results. I frequently see additional entries listed, seemingly
leftover from previous queries.

I have even added code to delete the previous queries before they are
created:

If ObjectExists("Queries", "qryUnionQuery") = True Then
MyDatabase.QueryDefs.Delete "qryUnionQuery"
MyDatabase.QueryDefs.Refresh
End If

but I still get the leftover record on the form, but NOT in the
tabular display of the UnionQuery results. The tabular display is
always what I expect to see. Where are the old results being stored?

I'm stumped. Thanks in advance for you help.

- Bernie

May 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
3
by: Matt O'Donnell | last post by:
Does anyone know how I can 'join' the results of one SQL query to the bottom of another? Eg. I have two queries: 1. SELECT Name, Surname FROM People WHERE Surname = Smith NAME ...
2
by: DS | last post by:
Hi, I'm building an Inventory form. I have a Product Form and ono that form I want to place a sub-form showing the sold products along with the Products that were received. I have a calculated...
3
by: matthewemiclea | last post by:
I am trying to display information in Access on a form that takes information from many different queries and puts them together on a spreadsheet or chart. Some specific info: The information I...
4
by: steves | last post by:
Hello All, I am trying to link to an existing database and extend the funcitonality by adding a phone call logging extension, so you can see a list of phone calls for a given customer. There...
19
by: Coward 9 | last post by:
HI, I saw in an example hello.aspx, there is a <form tagbeing used like <form runat="server> I search all html tag references and could NOT find "runat" attributes for <formtag. which...
1
by: martin DH | last post by:
Slightly related previous posts: (http://www.thescripts.com/forum/thread720001.html) and (http://www.thescripts.com/forum/thread708234.html). Okay, I've had to go back the drawing board a couple...
7
by: php_mysql_beginer911 | last post by:
Hi .. hope someone will help i am trying to figure it out why i cannot post string "union select" every time i try to post data which content union and select .. the page doesn't get posted and...
0
by: Hamayun Khan | last post by:
Hi All I am using the following query to select records from two tables. Select JobTitle,JobDesc,Scraped,logoimage,JobPostID,SchoolID,web,MemType,InstitutionName,PayScale,LEA,Contract as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.