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

Adding empty records

A similar question to mine was asked before with one reply back in 2006. I tried to use the information provided but was unable to make it work.

I created a database to print out a report that is the same as the original hand written form. The problem I'm running into with this report is when the last record prints and there are no more additional lines (i.e. if the document has 15 lines to be filled out, and if I print
from Access with only 10 records entered, 10 lines is all I get.).

I'd like to complete the additional lines using empty records (5 records per the previous example) since there are many times we will need to add information to the report by hand after it has been printed and we will need the lines.

here is what I was attempting to use from a previous post.

Expand|Select|Wrap|Line Numbers
  1. Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
  2. If Me.MoveCount < intLineCnt Then
  3. Me.MoveLayout = True
  4. Me.PrintSection = False
  5. Me.NextRecord = False
  6. Me.MoveCount = Me.MoveCount + 1
  7. Else
  8. Me.MoveLayout = True
  9. Me.PrintSection = True
  10. Me.NextRecord = True
  11. End If
  12. End Sub
  13.  
  14. Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
  15. Me.MoveCount = 0
  16. intLineCnt = CalcLinesToMove()
  17. End Sub
Any help would be much appreciated.

Thanks!
Jan 31 '13 #1
25 7040
Rabbit
12,516 Expert Mod 8TB
Use a union query to append blank records to the record source. No need to mess with code.
Jan 31 '13 #2
NeoPa
32,556 Expert Mod 16PB
If I'm not missing something, they would also need to restrict the number of records returned in the query to 15. This can be done using the TOP predicate of the SELECT clause. This can also be handled in the properties of a QueryDef by setting the Top Values property.
Jan 31 '13 #3
Rabbit
12,516 Expert Mod 8TB
Actually, though not stated, I believe the goal is to reach a multiple of 15. In which case, create a table with the numbers 1 through 15 and use a mod to return the number of blank rows you need to union.
Jan 31 '13 #4
NeoPa
32,556 Expert Mod 16PB
Rabbit:
I believe the goal is to reach a multiple of 15.
I'm inclined to agree, although the OP was specific in their explanation and that was for 15.

In case it's not clear though (and I had to think hard before I worked out what you might be suggesting), what I think you're suggesting is something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM   [OPTable]
  3. UNION ALL
  4. SELECT TOP (14 - (((SELECT Count(*)
  5.                     FROM   [OPTable]) - 1) MOD 15))
  6. FROM   [Rec15]
Feb 1 '13 #5
Rabbit
12,516 Expert Mod 8TB
Essentially yes. But it would be 15 subtract the mod and only if the mod is not equal to 0.
Feb 1 '13 #6
NeoPa
32,556 Expert Mod 16PB
Rabbit:
But it would be 15 subtract the mod and only if the mod is not equal to 0.
And how would that be coded, other than how I suggested, without having to repeat the subquery?
Feb 1 '13 #7
Rabbit
12,516 Expert Mod 8TB
Sorry, you were right. I missed the -1.
Feb 1 '13 #8
Thanks for the help but I am just not knowledgeable enough in this to be able to put it to use. Up to this point I have done everything using the wizards and it has been pretty fun... My experience using access is very limited. I like the idea of using queries though since I would not have to use the code, but I do not know how to implement this.
Thank you,
Frank
Feb 5 '13 #9
zmbd
5,501 Expert Mod 4TB
frankiejj98:
It's been such a long time since I was there with the Wizards as my friends. :)

OK, a small walk thru as I'd bet you're a tad shy on the SQL
- Create your second table as given in post 4
-Open the query editor.
-Change the view to SQL. -
[V2010] Ribbon, Create, Query, Design
Close the popup dialog without adding tables
You will now have a blank upper field and a grid below.
Easy way to SQL is to Right click in the field, select SQL View in the context menu. You can also select this from the Ribbon, or the bottom right hand corner.[/V2010]
-Copy and paste the SQL in the code box in NeoPa's post #5

Now here's where things will get troublesome if you don't know SQL so I'll do a break down:

SELECT * - This will select all of the fields in the table given in the table OPTable:
FROM [OPTable] You will need to change this to match your data table's name.
UNION ALL this is the magic that will allow you to get the empty records from the second table as given in post #4
SELECT TOP 14 Pull the first 14 records...
- ( less the calculated
((SELECT Count(*) returned count of the records in table OPTable by selecting all of records
FROM [OPTable]) from your data table Make sure you change the name!
- 1) subtract 1 from that number
MOD 15)) and calculate the remainder from 15 then append that number of records:
FROM [Rec15] the second table as given in post #4 and you will have to change this to the table name that you create.
Feb 5 '13 #10
Thank you all very much for your time. I will work on it as soon as I can....Hopefully this afternoon. I'm sure that I will be in touch.
Thanks again!
Feb 5 '13 #11
NeoPa
32,556 Expert Mod 16PB
Z explains that well.

I would just explain that the table names I used were purely for reference, and to mean something in this thread. OPTable just refers to the OP's (your) table. and Rec15 just indicates where you get the blank records that form the balance of the multiple of fifteen.

Before you use this you will need to create and populate this table. I suggest a name something like [tblBlank] in your actual project. It should have all the same fields that will be used in your report, as well as some type of ID field that holds unique values that can be sorted on. Unfortunately the TOP predicate only returns the exact number of items specified when the values of the sorted field(s) are different. This may be a problem with the SQL suggested. Give it a try and let us know the results. If we need to we'll find a way around that for you with some updated SQL.
Feb 5 '13 #12
Rabbit
12,516 Expert Mod 8TB
You can include a unique ID to get around that. Just don't put it on the report.

You don't technically have to include the fields you want in the table definition. It can just be a table with one field with the numbers from 1 to 15 and then in the SQL you can define the number of blank strings needed. That way, you can reuse the table.
Feb 5 '13 #13
Okay I gave it a shot and created a tblBlank with the same fields that are used on my report. My original table is tblEvidence. I used the SQL provided and changed the names to my particular tables but I get an error that says 'The SELECT statement includes a reserved word or argument name that is misspelled or missing, or the punctuation is incorrect.' I checked the spelling but do not see anything.
Expand|Select|Wrap|Line Numbers
  1. SELECT  *
  2. FROM     [tblEvidence]
  3. UNION ALL SELECT TOP (14 - (((SELECT Count(*)
  4.                     FROM   [tblEvidence]) - 1) MOD 15))
  5. FROM   [tblBlank];
  6.  
Feb 5 '13 #14
Rabbit
12,516 Expert Mod 8TB
You didn't specify which fields to select in your bottom query and so it thinks you're trying to select a field named from.
Feb 5 '13 #15
zmbd
5,501 Expert Mod 4TB
Rabbit:
I thought I try that... using a very simple select query against one field in my test db, I'm getting that same error if you even do something like
SELECT TOP (14 - 1)....
Appears the engine does not like calculated values.


<EDIT>
ALL, DISTINCT, DISTINCTROW, TOP Predicates
The value that follows TOP must be an unsigned Integer.
</EDIT>
Feb 5 '13 #16
Rabbit
12,516 Expert Mod 8TB
I've used it in SQL Server but not Access, if you can't use top, move it the WHERE clause on a field that numbers the records from 1 to 15.
Feb 5 '13 #17
NeoPa
32,556 Expert Mod 16PB
Rabbit:
You didn't specify which fields to select in your bottom query and so it thinks you're trying to select a field named from.
That's because my interpretation of your suggestion omitted that from the SQL (OOOoooops)! My bad there.

Expand|Select|Wrap|Line Numbers
  1. SELECT TOP (formula)
This doesn't work in Jet SQL! Well, that certainly sucks big time.

How about this :
Expand|Select|Wrap|Line Numbers
  1. SELECT Null AS [IDField]
  2.      , *
  3. FROM   [tblEvidence]
  4. UNION ALL
  5. SELECT [IDField]
  6. FROM   [tblBlank]
  7. WHERE  ([IDField] Between ((((SELECT Count(*)
  8.                              FROM   [tblEvidence]) - 1) Mod 15) + 2) And 15)
[tblBlank] needs records with just the [IDField] set and numbered from 1 to 15 (at least).
Feb 6 '13 #18
I am trying but still am not having any luck. Maybe I we can find a manual solution? I tried to add the blank records manually and it did work...however, it is printing the blank records first and then the actual records with data. If I could figure out a way to sort it the opposite way I could make this work manually...Any ideas?
Feb 6 '13 #19
Rabbit
12,516 Expert Mod 8TB
You need to describe what's not working. What did you try? What code did you use? What went wrong? Did you get error messages?

Why go manual when you can just set up an automated process? Just because you failed to set it up correctly a few times shouldn't discourage you from doing it the more efficient way.
Feb 6 '13 #20
NeoPa
32,556 Expert Mod 16PB
Have you tried including the [IDField] field as the first field for sorting by in your report? If Nulls appear in the wrong position you can easily change the SQL to return a zero (0) instead for the records returned by [tblEvidence].
Feb 6 '13 #21
Thanks Rabbit,
The error that is returned is 'The select statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.'
Here is the code that I am using:
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. ,*
  3. FROM [tblEvidence]
  4. UNION ALL SELECT TOP (14 - (((SELECT Count(*)              
  5.           FROM [tblEvidence]) - 1) MOD 15))
  6.           FROM [tblBlank]
  7.  
Thanks again!
Feb 7 '13 #22
Rabbit
12,516 Expert Mod 8TB
1) You have SELECT *,*. There's no need to select all the columns twice. That's certainly going to cause conflict as there will be two of every column with the same name.

2) You need to reread the posts because we determined that you can not use an expression in the TOP predicate and proposed an alternate solution. (Refer to NeoPa's post, #18). It's not quite right, but it gets you most of the way there, he forgot to select the rest of the columns in the blank table.
Feb 7 '13 #23
Okay, I followed the instructions from post# 18. I ran the query and get the following error msg: 'The number of columns in the two selected tables or queries of a union query do not match'. So just in case, I copied my tblEvidence and saved it as tblBlank. I already had the IDField created in tblEvidence. I'm not sure what else to do. I am really frustrated and I hope that it is not too frustrating for you...I am clearly over my head with this stuff. I understand if you do not want to continue with this thread.
Thanks,
Frank
Feb 8 '13 #24
zmbd
5,501 Expert Mod 4TB
That is a fluke of MS Access UNION queries.
The number of fields in each has to match:
SO lets back up a tad and use an example (forgive an old Chemist and TA, it's the only way I can make sense of my thoughts - I have to get them on "paper" sometimes :-), wait till you get old - it'll happen to you too (chuckle) )

OK
tbl_data
[data_pk] autonumber
[data_field1] (doesn't matter, just example)
[data_field2] (doesn't matter, just example)
[data_field3] (doesn't matter, just example)

tbl_blank
[blank_pk] number(long) (in this case records with values 1 thru 15)
[blank_field1] text(1) (in this case leave null, or enter a " " space)

Now, lets use the information provided in post #18 tweaked for this generic example - and I'm going to use hard coded fields for the example:

Expand|Select|Wrap|Line Numbers
  1. SELECT [data_pk],
  2.    [data_field1],
  3.    [data_field2] 
  4. FROM   [tbl_data] 
  5. UNION ALL 
  6.    SELECT [blank_field1] as F1,
  7.       [blank_field1] as F2,
  8.       [blank_field1] as F3
  9.    FROM   [tbl_Blank] 
  10.    WHERE  ([blank_pk] Between
  11.       ((((SELECT Count(*)
  12.           FROM [tbl_data]) - 1) Mod 15) + 2) And 15)
(please note, this SQL has been vetted against my test DB using the tables and records as indicated for MS Access 2010: [data_pk]=autnumber; [data_field1]=date; [data_field2]=text(50); [blank_field1]=text(1) are all null/empty value; [blank_pk]=number(long))

The main thing to notice here is that the number of fields in each "SELECT" portion are the same.
[edit - toddler playing with enter key :) - sigh]
So if you use the code from #18 as is, then you need to make sure that within the second "SELECT" following the "UNION ALL" has the same number of fields as the first one does in order for the query to work.
Feb 8 '13 #25
NeoPa
32,556 Expert Mod 16PB
Rabbit:
It's not quite right, but it gets you most of the way there, he forgot to select the rest of the columns in the blank table.
Not so much forgot, as misinterpreted your comment from post #13. i read that as meaning the number of fields didn't need to match. Now I reread it I see that wasn't what you said.

@FrankieJJ
Try the following, but include Null entries for all the fields in the second query that occur in the first (IE. [tblEvidence]).
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)
Feb 9 '13 #26

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

Similar topics

2
by: David | last post by:
Hi, I have an order form which has a field 'ProductID'. This form has a button on each record to open a new form linked by ProductID. This new form is a continuous form and obviously, only...
3
by: grlgeek | last post by:
I have a report for creating the switchboard labels for our phone system receptionist switchboard. The template has 12 records per column. I setup a report that will create the labels and put a...
2
by: Tor Inge Rislaa | last post by:
Prevent Adding new records in DataGrid Hi I have a DataGrid that I want to open for editing but the user should not be able to add new records. When I set the ReadOnly = False it is possible...
3
by: Tull Clancey | last post by:
Hi, hope someone can help with the following, I'm a bit stuck! I have a database table (Access) with an AutoNumber field. When I add data to the table I want to use the AutoNumber field, format...
2
by: ET | last post by:
Hi! I'll need help on what todo with this information in table... There has to be a unique on one column (Item ID, for inventory purpose) but in many cases that ID is not known... thus, many...
1
by: Brian Campbell | last post by:
I had a dataloss from a main table but had some backup records. I want to cut&paste say line: __33__|__01/04/99__|__165_|______KA__|__________WI___|__1251654_____ so that my table gets the...
2
by: Rico | last post by:
Hello, I'm formatting a report based on an existing controlled document. The document that I'm duplicating has a number of lines that the user fills our manually, but the database version of...
3
by: Flo100 | last post by:
Hi, I have a recordset which I have populated with a query. I have an empty recordset. I would like to take value of a field in every single record, which is a string. Search if the 4rth...
1
by: mlangley | last post by:
Hi there. I am trying to figure out a way to create a series of empty records in a database (ACCESS 2003). Basically, the table has 10 years of information by id. However, if there is no ID, then...
2
by: puT3 | last post by:
How can I make the report do not show any empty records? For example, in this table do not has address...I want the report only shows company that has address
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: 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...
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
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
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,...

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.