473,406 Members | 2,698 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,406 software developers and data experts.

How do we get multiple blank records appended to a record set in multiples of a given

zmbd
5,501 Expert Mod 4TB
A Z Saga:

You'd think that something like this would be so easily available on the net - and yet, it's not.
Do a search here on bytes and this same topic turns up over and over; however, with some surprisingly different solutions.
In one, VBA is used to draw the lines in based on the record count.

SO what Prompted my little walk thru fire today: A "problem" popped up where in we used to have 25 rows on a pre-printed that used to have the "template" grid and text pre-printed in the details section is now blank - cheaper I'm sure. However, without these extra rows, the sprawl all over the page looks, well, not so professional.

I'm thinking... HEY, we just solved this problem like just last week - whewho-and-fist-pump!

Find the thread: 946504-adding-empty-records

Made the 25 row table ([ID]={1,2,3,...24,25}), altered the SQL we have here... and it works like a dream for the 25 row pre-printed document.

YEA!

Now, thinking "green" (I know... thinking again) we have these 3 x 1 - Row labels on an 8-1/2x11 paper that I'm constantly having one or two blank labels that go to waste because we'll only print what is in the database que. These unprinted labels go to waste as they can only go thru the thermal printer once.

And when we need a few "blank" labels for those one off hand entries, we have a word document to print a few blank forms. (back to that green thing) I'm like, hey, just use that ole-add the blank record to the end and we're no longer wasting the label and we shouldn’t ever need to “hand” print the extras again!

(OK, NeoPa and Rabbit: get out your girdles, you'll have a chuckle with this)

So, tweak the 25 to 3 in the SQL and What Worked wonderfully for the 25 row... wouldn't work for the 3 per page.

.... puzzled expression ....

Extra labels, or not enough labels and so forth... it didn't help that I've three other people and instruments wanting my attention for other projects too! Print Preview is a wonderful thing!

So after a day of interruptions and doing the math, wouldn't have taken so long if I could have just worked out the math in peace, I finally hit on the solution to make another table with only three blank rows for the 3 per page - and that worked!

However, I don't want two tables with blank records out there and possibly yet a third or fourth depending on customer and lab needs... so what to do?

My final solution has to deal with how the [ID] field is numbered in tbl_blank.
I have a set of [ID]={3001,3002,3003}; [ID]={25001,25002,25003,...25024,25025}]
So if I needed 100 rows... {100001, 100002,...100100}

SO using the code block from the above thread that solved the 15 row issue:

Expand|Select|Wrap|Line Numbers
  1. SELECT Null AS [IDField] 
  2.      , * 
  3. FROM   [tblEvidence] 
  4. UNION ALL 
  5. SELECT [IDField] 
  6.      , Null 
  7.      , Null 
  8.      , ... etc 
  9. FROM   [tblBlank] 
  10. WHERE  ([IDField] Between ((((SELECT Count(*) 
  11.                              FROM   [tblEvidence]) - 1) Mod 15) + 2) And 15) 
  12.  

We modify as needed to use those [ID] ranges thus:
Expand|Select|Wrap|Line Numbers
  1. (first part of SQL omitted)
  2. (for the 3x3):
  3. UNION ALL  
  4.    SELECT [blank_pk] as F1, 
  5.           "", 
  6.           "" 
  7.    FROM   [tbl_Blank]  
  8.    WHERE  ([blank_pk] Between 
  9.       ((((SELECT Count(*) 
  10.           FROM [tbl_data]) - 1) Mod 3) + 3002) And 3003)
  11.  
  12. (for the 25 row form:)
  13. (first part omited...)
  14.           FROM [tbl_data]) - 1) Mod 25) + 25002) And 25025)
And there’s the end of my tale
-z
Feb 21 '13 #1
7 1351
Rabbit
12,516 Expert Mod 8TB
That's odd, I don't see why there would be a need for multiple sets of IDs. If it works for 15, it should work for 3. There must be something else going on. My first thought is that it was counting the wrong table.
Feb 22 '13 #2
zmbd
5,501 Expert Mod 4TB
That was my first thought too....
- and a few hours of head against the wall!!!!! @(

So, going back to the "if you're banging your head against the wall... you've missed something simple...." lesson from Dr. P.

I said to myself: "OK, let's see how this works:
I am going to break the SELECT portion of the conditional down into steps - working for the 3x1 setup"

I know the columns don't quite line up... however from left to right we take the action in the header and apply to the result of the immediate left column.
Expand|Select|Wrap|Line Numbers
  1. Lets take the equation: ((((SELECT Count(*) FROM [tbl_data]) - 1) Mod 3) + 2) And 3)                                    
  2. Record                                    
  3. Count   Count(*)    -1     mod 3    +2     To give the conditional of
  4. 0          0        -1        2      4    [ID] BETWEEN 4 AND 3
  5. 1          1         0        0      2    [ID] BETWEEN 2 AND 3
  6. 2          2         1        1      3    [ID] BETWEEN 3 AND 3
  7. 3          3         2        2      4    [ID] BETWEEN 4 AND 3
  8. 4          4         3        0      2    [ID] BETWEEN 2 AND 3
  9. 5          5         4        1      3    [ID] BETWEEN 3 AND 3
  10. 6          6         5        2      4    [ID] BETWEEN 4 AND 3
  11. 7          7         6        0      2    [ID] BETWEEN 2 AND 3
  12. 8          8         7        1      3    [ID] BETWEEN 3 AND 3
  13. 9          9         8        2      4    [ID] BETWEEN 4 AND 3
  14. 10        10         9        0      2    [ID] BETWEEN 2 AND 3
  15. 11        11        10        1      3    [ID] BETWEEN 3 AND 3
  16. 12        12        11        2      4    [ID] BETWEEN 4 AND 3
So when the "blank table" has more than three records where [ID]={1,2,3,...(n>=4)}, the "data table/query" record count is zero or MOD3=0; we have the conditional[ID] BETWEEN 4 AND 3; thus, returning Two records from the blank table to be appended to the the record set via UNION ALL when we're expecting nothing to be returned and other weirdness occurs.

Looking at the above, you'll see other weirdness too.
Reducing the [ID] to [ID]={1,2,3} either by eliminating records or via the groups then when Mod3=0 or RC=0 then no [ID] fall within the conditional.

and there you have it.


Oh, just noticed that I didn't change the Primary Key field name in my posted SQL....
[Blank_PK] is the equivalent to the [ID] field and I have used the two field names interchangeably (very poor oversight on my part sorry)... please don't let that confuse anyone. They are both the same reference to the Primary Key of the table containing the blanks. I dislike using the generic [ID] and opt for a more descriptive field name...
Feb 22 '13 #3
Rabbit
12,516 Expert Mod 8TB
How come you're adding 2? Shouldn't you add just 1?
Feb 22 '13 #4
zmbd
5,501 Expert Mod 4TB
you can certainly try with adding just one, however, when you do so:

Expand|Select|Wrap|Line Numbers
  1. Record Count    To give the conditional of
  2. 0    [ID] BETWEEN 3 AND 3 (now returns one blank record)
  3. 1    [ID] BETWEEN 1 AND 3 (now returns three blank records)
  4. 2    [ID] BETWEEN 2 AND 3
  5. 3    [ID] BETWEEN 3 AND 3 (now returns one blank record)
  6. 4    [ID] BETWEEN 1 AND 3
  7. 5    [ID] BETWEEN 2 AND 3
  8. 6    [ID] BETWEEN 3 AND 3
  9. 7    [ID] BETWEEN 1 AND 3
  10. 8    [ID] BETWEEN 2 AND 3
  11. 9    [ID] BETWEEN 3 AND 3
  12. 10    [ID] BETWEEN 1 AND 3
  13. 11    [ID] BETWEEN 2 AND 3
  14. 12    [ID] BETWEEN 3 AND 3
  15.  
Feb 22 '13 #5
Rabbit
12,516 Expert Mod 8TB
I should pay closer attention. Try:
Expand|Select|Wrap|Line Numbers
  1. ID >= 1
  2. AND
  3. ID <= (2 - (((
  4.    SELECT COUNT(*)
  5.    FROM tableName
  6. ) - 1) MOD 3))
Feb 22 '13 #6
zmbd
5,501 Expert Mod 4TB
I'll have to try that when I get back to the lab Monday or Tuesday (provided someone hasn't pressed the self destruct button again!)

I should have used the "range method" as you've given instead of the BETWEEN method - I've done so in the past when joining subqueries of lab data together for reports. Guess I started down that road with the BETWEEN and like a dog-with-a-bone couldn't let it go... besides, with the day I was having, it was a puzzle to solve to relieve the stress of the day! It just bugged me that it wasn't a generic construct!

(I know, Chemist programs/designs databases and solves logic puzzles to relieve stress... never said I was sane)

Now a thought, how does the performance between the two methods compare?
Feb 22 '13 #7
Rabbit
12,516 Expert Mod 8TB
I wouldn't expect the performance to be any different. I do expect the results to be different.

This can never return results.
>= 1 AND <= 0

This will flip the numbers and be able to return results.
BETWEEN 1 AND 0
Feb 25 '13 #8

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

Similar topics

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...
1
by: tjm0713 | last post by:
Not sure this can be done but here is my current situation. I have a table containing millions of records. Each record has 28 fields. One of the fields I am trying to return the single record for...
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
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.