473,378 Members | 1,360 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,378 software developers and data experts.

Chapter 2: How do we get multiple blank records appended ... a z-saga

zmbd
5,501 Expert Mod 4TB
Chapter 2 of the Z’s Saga or:
The Curious Difference Between what the Union Query Returns and what the Report Prints
Prolog:
This is where I started as there was what I thought a good solution for a similar problem: 946504-adding-empty-records
Chapter One of the Saga – in which the original solution is reworked.
(Very quickly, we’re trying to fill a page with a number of records in a multiple of 3 by appending enough blank records to the report to make three records per page so as not to waste the labels on the page).

Chapter 2:
So let’s start with the final solution using Rabbit’s “Range” method given in the prior thread instead of the “Between” we started out with resulting in the following SQL in my Database (we’ll just move things over to my field names at this point as I’m starting to get confused and it’s certainly much easier for me to keep track of things if I’m using my own thoughts (?) ):
(Notice here that MSAccess has used the Dot instead of the Bang (!?) between the table name and the related field name - curious. Other than stepping the SQL, I’ve cut and pasted directly from the query):
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    tbl_printque.printque_pk, 
  3.    tbl_printque.printque_fk_inventory, 
  4.    tbl_printque.printque_printdate, 
  5.    tbl_Inventory.Inventory_ItemTrackingID, 
  6.    tbl_Inventory.Inventory_Serial, 
  7.    z_product_text, 
  8.    tbl_printque.printque_reportname
  9. FROM [qry_for_rpt_newinventorytag]
  10. UNION ALL SELECT [blankrow_pk] 
  11.      , Null 
  12.      , Null 
  13.      , Null 
  14.      , Null
  15.      , Null
  16.      , Null 
  17. FROM   [tbl_blankrow] 
  18. WHERE  (([blankrow_pk]>=1) 
  19.    AND ([blankrow_pk]<=
  20.       (2- ((
  21.          (SELECT Count(*) 
  22.           FROM [qry_for_rpt_newinventorytag]) - 1) 
  23.       mod 3))));
(keep track of that “UNION ALL” ) [z_product_text] is a calculated field in the query [qry_for_rpt_newinventorytag] provided here for reference:
Expand|Select|Wrap|Line Numbers
  1.  SELECT 
  2.    tbl_printque.printque_pk, 
  3.    tbl_printque.printque_fk_inventory, 
  4.    tbl_printque.printque_printdate, 
  5.    tbl_Inventory.Inventory_ItemTrackingID,, 
  6.    tbl_Inventory.Inventory_Serial, 
  7.    [tbl_products]![product_model] & "_" & [tbl_products]![product_name] 
  8.        AS z_product_text, 
  9.    tbl_printque.printque_reportname
  10. FROM tbl_Products
  11.    INNER JOIN (tbl_printque 
  12.       INNER JOIN tbl_Inventory 
  13.            ON tbl_printque.printque_fk_inventory = tbl_Inventory.Inventory_pk) 
  14.       ON tbl_Products.Product_PK = tbl_Inventory.Inventory_FK_Products
  15. WHERE (((tbl_printque.printque_printdate) Is Null) 
  16.     AND ((tbl_printque.printque_reportname)="rpt_newinventorytag")); 
So… the Union Query in the first code block returns exactly the correct number of records from the blank table to make the record set count a multiple of three – as expected.
However, when used as the record source for the report, there are appended three empty records. To clarify, if there is one Inventory Item pending report, when the UQ is ran there are only three records, if there are seven items, then the query returns nine records (7+2blank), and so forth. The report however returns the number of items plus three blank records (at least it append the entire table of 25 blanks! :-) )
Going back to that first code block, changing “UNION ALL” to simply “UNION” returns the expected number of records both within the query and for the report. If the query has 2 assets it appends 1 blank and the report only has 2 assets and 1 blank… instead of 2 assets and 3 blanks as in the case with the “ALL”.
So what is up with that? I thought I understood how the UNION/UNION-ALL clauses worked, and yet I just cannot seem to make sense of this… there are no duplicated values and so forth… and why would the Query run and return the expected results using either method and yet the report based on this very same query will only return the expected result in only one case.
Feb 25 '13 #1
3 1174
Rabbit
12,516 Expert Mod 8TB
If there's no duplication in the data, then I would expect the union and union all to return the same results.

I don't, however, understand why it would act differently when used in a report. Can you attach the database?
Feb 25 '13 #2
zmbd
5,501 Expert Mod 4TB
As far as the query goes, the result set is the same.
Just when it goes to the report.
I'll see what I can do about posting the database. They took my zip program with the last round of security updates. sigh.
One thing to note is that the database is in v2010.
Feb 25 '13 #3
Rabbit
12,516 Expert Mod 8TB
Oh, I have 2007. If you are unable to attach it, I'll see if I can find some time to mock it up.
Feb 26 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John | last post by:
Hello all, new problem... When I go to my secondary page of results after I fill info out on a form on the first, I get 3 blank entries automatically inserted into the mysql tables. This second...
4
by: John | last post by:
Anyone know why blank records would be input into the database from a form? Everytime I click submit I get 3 entries at a time entered in for no reason on top of the original data.
5
by: John | last post by:
Hey everyone, I keep getting multiple blank records entered along with my data everytime I submit my form. On the first page is the form itself without any code. On the 2nd page that it goes...
1
by: anmar | last post by:
I'm trying to figure out how to select all the records in one table which have multiple specified records in a second table. Here's a simplified version of my problem. I have two tables,...
6
by: kenshiro | last post by:
Hi All, I'm having a problem with some VBA code in one of my Access 2003 databases. I'm getting the following error when running code behind a command button on a form: "Item not found in this...
4
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that...
2
by: propoflady | last post by:
When I do the following union query - it works but it gives me blank records then my list SELECT , FROM BuyerListName UNION SELECT , FROM Buyers ORDER BY ;
0
by: cannonpm | last post by:
Greetings and salutations. I have developed an A2K3 MDB and have a search form modeled after Allen Browne's search form (http:// allenbrowne.com/ser-62.html). It works well except for records which...
1
by: colin-whitehead | last post by:
I have 2 tables tblReports primary key UPN, plus numeric fields Effort, Attain, etc tblComments numeric primary key ID & textfield Text In the Query I select each record from tblReports...
25
by: NDayave | last post by:
How do, I have a form that outputs addresses in a format that can be printed on to 3x7 label paper for envelopes. What I want is a way to enter blank (or " ") rows to the query result where the...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.