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 user specifies so no label is printed in that particular place.
I am aware of the problems of inserting blank records to tables. I say this as the other forums I have searched all reply with disbelief and condemnation for inserting blank rows into a database rather than offering support to the question asked.
I am not trying to store the blank rows, just insert them into the Report's record source at user specified intervals.
For example, the rows populate the labels as such:
Row 1 | Row 2 | Row 3
Row 4 | Row 5 | Row 6
etc
If there is no label in the space Row 3 would be printed on, I want to be able to output the rows as:
Row 1 | Row 2 | BLANK
Row 3 | Row 4 | Row 5
etc
Is there anyway of adding the blank record in at the correct place without resorting to creating a recordset line by line?
Many Thanks,
NDayave
I have found the simple little trick I was after.
On the 'Rows to skip' form, store the row numbers in a global string variable with a comma at the start and end of each number, Eg: ",2,4,6,7,9,"
In the Report, enter the following code and the specified rows will be passed over, continuing with the next row in the recordsource: -
Option Compare Database
-
Option Explicit
-
-
Dim fBlankNext As Boolean 'Pass over next Label?
-
Dim intLine As Integer 'A line counter.
-
-
-
Private Sub Report_Open(Cancel As Integer)
-
'Zero the Line Counter
-
intLine = 0
-
End Sub
-
-
-
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
-
'Pass over the First Label if Necessary
-
fBlankNext = (InStr(1, <<BLANK ROW LIST VARIABLE>>, "," & intLine + 1 & ",", vbTextCompare) > 0)
-
End Sub
-
-
-
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
-
'Increment Line Counter
-
intLine = intLine + 1
-
-
'If passing over the next label, pass over and check if passing over the one after
-
If fBlankNext = True Then
-
Me.PrintSection = False
-
Me.NextRecord = False
-
fBlankNext = (InStr(1, <<BLANK ROW LIST VARIABLE>>, "," & intLine + 1 & ",", vbTextCompare) > 0)
-
Else 'If not passing over, print detail and check if passing one after
-
Me.PrintSection = True
-
Me.NextRecord = True
-
fBlankNext = (InStr(1, <<BLANK ROW LIST VARIABLE>>, "," & intLine + 1 & ",", vbTextCompare) > 0)
-
End If
-
End Sub
-
-
-
Found and adapted from http://www.allenbrowne.com/ser-12.html 25 7367 NeoPa 32,556
Expert Mod 16PB
Yes.
You can be creative in a query and build the labels report on the back of the query.
I don't think we have enough detailed info here to go much further for now, but it will probably involve a table of enough items to populate a full page at least. I'll stop there as I don't want to have to back-track when I get the details.
Basically, I have a mailing list generator that produces a list of addresses based on the criteria selected.
Ie: Forename, Surname, Address1, Address2, etc, etc
The query is generated via VBA code based on the selections made by the user. As this involves both Individual Contacts and Organisations, there is the possibility of a Union being used, but not always.
Why would it require a full page worth of labels? I ask as they may only print a couple of labels in one sitting, but several pages in another.
What sort of information are you after?
NeoPa 32,556
Expert Mod 16PB NDayave: Why would it require a full page worth of labels? I ask as they may only print a couple of labels in one sitting, but several pages in another.
I was thinking along the lines of a driving data source, that could be used to link your main data to. This may not be very clear so I will try to clarify :
A driving data source is one that you JOIN another source to, using either a LEFT or RIGHT JOIN (See SQL JOINs for more details of this). For now I will continue using the LEFT JOIN concept as that seems simpler to understand. If you want a blank record anywhere, the data source you use must be able to identify that item, and it would be set up so as not to find a matching record from your main data. With no details of how the items are identified (what indexes may be used) I'm not in a position to get into details. NDayave: What sort of information are you after?
Some more detailed understanding of terms like user determined. On its own it provides no information at all. If you can explain how a user specifies this and what determines a selected item, then we have something we can build on.
Sometimes one cannot tell what data is required without the context of the question. That is why it is mainly down to you to include what is required. I can point to items that may be necessary, but other information, when supplied, may make some of that superfluous.
Using your example where record #3 should be blank, you need to consider what you have that could identify that record #3 is blank. but that all others match. This is true whether you do this via a table (creating blank records somewhere) or do it in a LEFT JOIN query.
Well, I've made a very idiot proof query generator for use by the most computer illiterate people around. It functions by making sentences that correspond to the generated SQL.
Eg: Include | Organisations | Working in the Area of | Schools
returns the SQL that brings out all schools.
From here they can add more groups of individuals/organisations by adding more "Include" criteria, remove certain inds/orgs by adding "Exclude" criteria and refining either by adding "And" criteria.
Eg:
Include | Contacts | That are a part of | School 1
And | -------- | Aged | 11 to 15 years old
Exclude | Contacts | That are a part of | Event 1
Would return all the contacts aged 11-15 that go to School 1 and are not currently associated with Event 1.
When only Individuals are involved, the FROM and WHERE criteria is: -
FROM (tblSource RIGHT JOIN ((tblContact LEFT JOIN (tblLinkType RIGHT JOIN tblLink
-
ON tblLinkType.TypeID = tblLink.TypeID) ON tblContact.ContactID =
-
tblLink.ContactID) LEFT JOIN tblSourceRel ON tblContact.ContactID =
-
tblSourceRel.ContactID) ON tblSource.SourceID = tblSourceRel.SourceID) LEFT JOIN
-
(tblOrg LEFT JOIN (tblOrgArea RIGHT JOIN tblOrgAreaRel ON tblOrgArea.OrgAreaID =
-
tblOrgAreaRel.AreaID) ON tblOrg.OrgID = tblOrgAreaRel.OrgID) ON tblLink.OrgID =
-
tblOrg.OrgID
-
-
-
WHERE ((((tblContact.ContactID IN ( SELECT tblContact.ContactID FROM tblContact
-
INNER JOIN tblLink ON tblContact.ContactID = tblLink.ContactID WHERE (
-
tblLink.OrgID = 10)))) AND (tblContact.ContactID IN ( SELECT tblContact.ContactID
-
FROM tblContact WHERE ( DateDiff('yyyy', tblContact.DateOfBirth, Date()) -
-
IIF(Format(tblContact.DateOfBirth, 'mmdd') > Format(Date(), 'mmdd'), 1, 0) >=
-
11)AND( DateDiff('yyyy', tblContact.DateOfBirth, Date()) -
-
IIF(Format(tblContact.DateOfBirth, 'mmdd') > Format(Date(), 'mmdd'), 1, 0) <=
-
15))))) AND ( tblLink.OrgID <> 25)
-
The WHERE is generated in VBA from the Criteria list box on the form line by line adding in the correct bracketing and criteria to add the WHERE clauses in the correct order.
When Organisations are being selected as well as Individuals, the same thing happens with the relevant FROM and WHERE etc and is added as a UNION to the final output.
I am currently thinking about adding the search result to a recordset line by line and inserting the blank rows where specified, then basing the report on the recordset instead. Is there any other way of doing this?
NeoPa 32,556
Expert Mod 16PB
That'll teach me to ask for more info :D
There is much here to go through and I'm currently in a rush. I'll have to look at this again tomorrow (I'm out this evening) and see if I can understand enough to help you go forward with this. I won't ridicule the idea of using a temporary holding table for this though. Maybe we can find a purer solution, but often situations don't lend themselves easily to such solutions.
I think I'll enjoy going through this anyway. I love it when people come up with innovative - outside the box - type scenarios.
NeoPa 32,556
Expert Mod 16PB
As an addendum, would you mind posting a copy of your database for me to have a closer look. I can't help feeling this will be hard to explain clearly and easily without an example to play with. I include below some instructions on how best to do that on here (Not all may be 100% relevant in your case but it's a template post) : When attaching your work please follow the following steps first : - Please consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
- If the process depends on any linked tables then make local copies in your database to replace the linked tables.
- If you've done anything in steps 1 or 2 then make sure that the problem you're experiencing is still evident in the updated version.
- Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
- Compact the database (Tools / Database Utilities / Compact and Repair Database...).
- Compress the database into a ZIP file.
- When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.
It's also a good idea to include some instructions that enable us to find the issue you'd like help with. Maybe some instructions of what to select, click on, enter etc that ensures we'll see what you see and have the same problems.
PS. If you feel there is too much of a sensitive nature in it then feel free to ignore this request. It is simply to make the process easier. It's not a pre-requisite for posting or getting help.
I have attached the relevant parts of the List generator and stripped most other things out. The lists can still be generated as they would normally.
I have PM'd the Zip password.
Let me know what you think.
NeoPa 32,556
Expert Mod 16PB
Thanks for this. I have also received the password safe & sound. I hope to get time to look at this properly over the weekend, after which I'll comment further.
Good morning,
Not to hijack the thread or anything, but I worked on this exact problem recently, except in the context of smaller mailing labels that come 30 to a page, arranged in three columns and ten rows.
My users were having the same problem...they would print out say five mailing labels, and the next time around need to start on the sixth label. So I made a label generator that would allow them to pick the row and column they wanted to start on and it works nicely.
Let me know if you're interested.
Pat
That would be very kind of you Pat.
Even if it doesn't work I'm sure I'll learn something new.
@NDayave
I have two drop down boxes that allow the user to pick the row and column they want to start at, and calculate the label number based on those. - Dim bytLblNbr As Byte
-
bytLblNbr = 3 * (Me.cboRowNbr - 1) + Me.cboColNbr
-
-
For j = 1 To bytLblNbr - 1
-
DoCmd.RunSQL "INSERT INTO tblTemp VALUES (Null, Null, Null, Null, Null, Null, Null)"
-
Next j
-
-
DoCmd.RunSQL "INSERT INTO tblTemp VALUES ('" & Me.txtNameLast & "', '" & Me.txtNameFirst & "', '" & Me.txtStreet & "', '" & Me.txtAptNo & "', '" & Me.txtCity & "', '" & Me.txtState & "', '" & Me.txtZip & "')"
When you open the report, you can set the record source to 'tblTemp'. This puts the necessary null records in the table first and then tags on my address record from the form. In this example, I'm just tagging on a single address from a form, but that last INSERT can easily be modified to add on multiple records, which is what I do in the operational version of my application.
Let me know what you think.
Pat
We'd thought about temporary tables, but as this is a regular operation that can involve hundreds of rows we are trying to avoid it.
I also want to be able to skip certain labels in case they have ruined some on a sheet (See post original post).
I am hoping for a solution that can add in blank rows into the SQL, which I know is possible in other platforms.
The basic idea for this is something I got from another forum where Allen Browne posted, by the way. So it isn't entirely my idea.
There is another method which involves having a table of null records, and using a UNION ALL to join the appropriate number of those null records to whatever set of records you want to print. I did in fact try this as well, and it works, but in my opinion it is a more complicated means to the end.
Pat
@NDayave
Well, it's just one temporary table, and you can delete it after the operation if you don't want it hanging around your database.
If you are looking to skip some labels in the middle of the data rather than just at the beginning...I would need to think about that one some more.
Pat
NeoPa 32,556
Expert Mod 16PB
I now have the db working, and I can see how to select items, or even predefined criteria. What I'm struggling to understand (and this is fundamental to any progress) is why labels should be determined to be blank. If an item is in the list it should print a label. If not then it shouldn't (and wouldn't).
My initial musings, assuming that some items need to stay in the list yet not create a label, would be to have some sort of flag in the record source that indicates your requirement (To print or not to print. That is the question!). The Control Source of the controls on your report would then simply say : - =IIf([Flag],[AddressLine1],Null)
-
=IIf([Flag],[AddressLine2],Null)
-
...
Does that make sense?
I expect with a better understanding of what determines a blank label we may get a better solution if this isn't good for you.
NeoPa 32,556
Expert Mod 16PB
I have just spoken with Mary (MSquared) and she feels that you are trying to avoid printing on missing, damaged or otherwise pre-used labels on a sheet. Can you confirm this for me please.
Yes, Mary is correct; I want to be able to specify and 'pass over' any labels that are not suitable for printing on the sheet.
I am not so worried about how to determine which labels to pass over, more how to add in either the blank rows to the query result or blank detail sections in the report.
NeoPa 32,556
Expert Mod 16PB
Well, the first step then obviously, is to consider how you will get the operator to specify which labels to skip. Is it limited to the first sheet? I would suggest you design a form of some sort which must clearly be based on data in a table of some kind. A temporary table could work, although I'd favour a bespoke table that handled records for the particular run. It would probably need to handle identifying the user so that multiple users could work on it at the same time. For a set of records that match your labels you will need to consider how you will start. How many labels to handle of course.
Once that has been determined you can use RecordSet processing to identify each valid label with a record of your data, then build the report based on a query linking the two.
Does that all make sense?
This database will only be used by one user at a time, so I don't have to worry about multiple users.
In order to maintain simplicity, I will have the form resemble the Label paper, allowing the user to click the labels that they wish to pass over. If recordset processing is to be used, why bother with the Tables? Seems like an extra step in the process.
My original thoughts were to have the form look like the label paper, with clickable labels that store the label numbers (multiplied by the page number is another page is added) on the form to be used in a recordset when the report opens.
So the process would be:
Click Labels 3 and 6 --> 3 and 6 stored on the form --> Report opens --> adds data to recordset from Query with blanks in row 3 and 6 and updates RecordSource
I thought this was a little inefficient and was hoping for some SQL side commands to pass over rows. What are the benefits of using the tables over a RecordSet on Report_Load?
@NDayave
A report's recordsource must be set to a query name, table name, or SQL string. You'll get an error if you attempt to assign a recordset.
You could using something like this (pseudo-code) to build a temporary table which will serve as the report's recordsource:
Let rst be the recordset that holds your data and j be an integer counter. - rst.MoveFirst
-
j=1
-
-
While Not rst.EOF
-
If (label #j marked for printing) Then
-
'Insert current rst into tblTemp
-
'rst.MoveNext
-
Else If (label #j marked to be skipped) Then
-
'Insert blank record into tblTemp
-
End If
-
-
j=j+1
-
Wend
Provided that tblTemp does not get ordered differently between the end of this code and loading the report, you can set the report's recordsource to be tblTemp and get blank labels interspersed amongst your printed labels.
Pat
NeoPa 32,556
Expert Mod 16PB NDayave: In order to maintain simplicity, I will have the form resemble the Label paper, allowing the user to click the labels that they wish to pass over.
That's pretty much what I had in mind. Remember that if it's to be much use it must cover at least as many records as the labels you require to print. Any labels selected to be skipped would increase that number of course. NDayave: If recordset processing is to be used, why bother with the Tables? Seems like an extra step in the process.
Because you cannot build your report on a Recordset (As Pat says). NDayave: My original thoughts were ...
I thought this was a little inefficient and was hoping for some SQL side commands to pass over rows. What are the benefits of using the tables over a RecordSet on Report_Load?
As per previous points you cannot use a recordset to drive a report.
As for some clever SQL to apply to the table to get what you need without any recordset processing, I'm afraid you may be underestimating this issue somewhat. This is not something that lends itself well to SQL. SQL deals with recordsets. Relative positions are anathema to SQL except where Aggregate functions are used, and even that is not what it's mainly about. You will need some pretty fiddly SQL anyway, but it won't do what you're after alone if I know anything of the matter. You will need to prepare some master data on which to hang your main label data.
I have found the simple little trick I was after.
On the 'Rows to skip' form, store the row numbers in a global string variable with a comma at the start and end of each number, Eg: ",2,4,6,7,9,"
In the Report, enter the following code and the specified rows will be passed over, continuing with the next row in the recordsource: -
Option Compare Database
-
Option Explicit
-
-
Dim fBlankNext As Boolean 'Pass over next Label?
-
Dim intLine As Integer 'A line counter.
-
-
-
Private Sub Report_Open(Cancel As Integer)
-
'Zero the Line Counter
-
intLine = 0
-
End Sub
-
-
-
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
-
'Pass over the First Label if Necessary
-
fBlankNext = (InStr(1, <<BLANK ROW LIST VARIABLE>>, "," & intLine + 1 & ",", vbTextCompare) > 0)
-
End Sub
-
-
-
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
-
'Increment Line Counter
-
intLine = intLine + 1
-
-
'If passing over the next label, pass over and check if passing over the one after
-
If fBlankNext = True Then
-
Me.PrintSection = False
-
Me.NextRecord = False
-
fBlankNext = (InStr(1, <<BLANK ROW LIST VARIABLE>>, "," & intLine + 1 & ",", vbTextCompare) > 0)
-
Else 'If not passing over, print detail and check if passing one after
-
Me.PrintSection = True
-
Me.NextRecord = True
-
fBlankNext = (InStr(1, <<BLANK ROW LIST VARIABLE>>, "," & intLine + 1 & ",", vbTextCompare) > 0)
-
End If
-
End Sub
-
-
-
Found and adapted from http://www.allenbrowne.com/ser-12.html @NDayave
Glad to see that you got it to work out. Clever use of the InStr function. I like it!
Pat
NeoPa 32,556
Expert Mod 16PB
Very nice solution. I had no idea that setting Me.NextRecord to False ensured the same record was processed again in a report. Perfect for this scenario.
@NDayave
Hi there, is it possible to get a copy of the file.
thanks heaps
Sign in to post your reply or Sign up for a free account.
Similar topics
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.
|
by: Lin Ma |
last post by:
Greetings,
In my search application, user can type a number to search. I use LIKE in my
query.
If a query result generates over 10,000 recordsets, it may several minutes
to run.
Is there a...
|
by: Surajit Laha |
last post by:
I am firing a query like:
SELECT TaskName, StartDate FROMTasks
WHERE StartDate >= '01-Aug-2003'
Now the result comes as:
TaskName StartDate
--------------------------
Task1 ...
|
by: vito |
last post by:
after executing the query, say it returns 1000 results.
if i just want to do some sampling and like to have a look on 4 of them,
how can i refer to these 4 random records out of 1000? i'm working...
|
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...
|
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 ;
|
by: Simon Verona |
last post by:
I have the requirement for address label printing within my software. I
have a name and address list in a ado.net in-memory dataset - I'd like a
pre-built software library which will display a...
|
by: Muddasir |
last post by:
i am having problem in printing the query result from MySQL db...
actually i am developing a very simple search module.
when the user select category from the given categories in drop down...
|
by: CCHDGeek |
last post by:
How can I tell if a query result empty (ie there are no records with the specified criteria). I want to change a form's design based on the result of the query it is based how. Does anyone know how...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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: 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,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: 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...
| |