473,748 Members | 6,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Crea teQueryDef("qry MattersQuery", "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 "qryMattersQuer y" =,
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
"qryExpiringLis t". 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.Crea teQueryDef("qry UnionQuery",
"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("Q ueries", "qryUnionQuery" ) = True Then
MyDatabase.Quer yDefs.Delete "qryUnionQu ery"
MyDatabase.Quer yDefs.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 2684
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...@gmai l.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.Crea teQueryDef("qry MattersQuery", "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 "qryMattersQuer y" =,
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
"qryExpiringLis t". 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.Crea teQueryDef("qry UnionQuery",
"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("Q ueries", "qryUnionQuery" ) = True Then
MyDatabase.Quer yDefs.Delete "qryUnionQu ery"
MyDatabase.Quer yDefs.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
5520
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, UPDATE, DELETE) which are controlled by a web frontend and the table records are manipulated to control the permissions. Example: The Press Release section record would look like this: Username: John Doe Function Name: Press Release
3
12885
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 SURNAME
2
2285
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 field to show me what my current inventory is. However, I want to only use one Sub-Form as oppossed to two. When I try to set up a query using the Products table in the center and Orders on one side and Sales on another Access can't return...
3
12732
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 am displaying consists of a work order schedule(for the current date), work orders completed , work orders not completed, a past due schedule, past due completed, and past due not completed. These are grouped by workcenters. Therefore, one...
4
1372
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 are two similar address tables (USA and international), which are almost the same except for some shipping addresses. The fields I'm interested in are all the same. So, I have:
19
2153
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 reference should I use in order to find that?
1
1295
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 of times on this one (it's all based on an data import of which I don't have control). My new problems is, I think, in my SQL. I have a form (Search Compile Form) that provides the criteria for a query (Search Compile Query) that answers back...
7
2934
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 it shows error page not found on this server i googled and found some people use union and select to hack sites (mysql injection) i guess the server i am using has some kind of filter and if a post string content "union select" ... it simply...
0
1574
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 ContractType,HoursAbl,StartDate,ClosingDate,asap from tblJobScrap Union ( SELECT tblJobPost.JobTitle,tblJobPost.JobDesc,Scraped,tblSchools.logoimage,tblJobPost.JobPostID,tblJobPost.SchoolID,tblSchools.web,cast(tblJobPost.MemType as nvarchar(255)) as...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.