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

Batch Print

2 2Bits
One major function of my database will be to print labels to be used for solicitation. Not all labels will be printed at the same time and I need a way to not repeat printing. I have little experience in VBA and I'm sure there is a better, quicker way to do what I've managed to do thus far. But I am stuck on how to finish this out.

Database Structure:
tblCo with fields: pkCoID, strCo, strAddress, strZip, fkBatch, ysnLabels
tblBatch with fields: pkBatch, dteBatchCreated
qryCo joins the tables
qryTop30 filters 30 companies without batch id's and is used for creating the batches
qryToPrint filters companies already in a batch but that have been printed yet.
frmLabels will essentially be the print dialogue (and is where I'm stuck)

Because the labels print 30 per page, I have code to create batches in groups of 30. The code executes by cmdBatch button.
I have a textbox on frmLabels for the user to enter the number of pages to print.
How do I then use that input to select that many batches and then print when user clicks cmdPrint?
And then once those labels have been printed, I want to change the ysnLabels from 0 to -1 so they aren't printed again.
I have it to where I can select 1 batch for printing, but what about multiples?

The code for creating batches is working:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmdBatch_Click()
  2.     Dim db As DAO.Database
  3.     Dim rs As DAO.Recordset
  4.     Dim strSql As String
  5.     Dim lngBatch As Long
  6.     Dim i As Integer
  7.     Dim mb As Integer
  8.  
  9.     m = Me.txtMaxBatch.Value
  10.  
  11.     If mb = 0 Then
  12.         MsgBox "All labels have been batched."
  13.     Else
  14.         For i = 1 To mb
  15.             Set db = CurrentDb()
  16.             Set rs = db.OpenRecordset("tblBatch", dbOpenDynaset, dbAppendOnly)
  17.             rs.AddNew
  18.                 rs!BatchCreated = Now()
  19.                 lngBatch = rs!pkBatch
  20.             rs.Update
  21.             rs.Close
  22.  
  23.             strSql = "UPDATE qryTop30 Set fkBatch = " & lngBatch & " WHERE ysnLabels = 0;"
  24.             db.Execute strSql, dbFailOnError
  25.  
  26.             DoCmd.Requery qryTop30
  27.         Next i
  28.     End If
  29.  
  30. Exit_Handler:
  31.     Set rs = Nothing
  32.     Set db = Nothing
  33.     Exit Sub
  34.  
  35. Err_Handler:
  36.     MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "cmdCreate_Click()"
  37.     Resume Exit_Handler
  38.  
  39. End Sub
I can print 1 Batch. How do I print x number of batches and then mark those batches as printed using the ysnLabels?
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrint_Click()
  2. 'On Error GoTo Err_Handler
  3.     Dim strWhere As String
  4.     Const strcDoc = "rptLabels"
  5.     Dim i As Integer
  6.     Dim p As Integer
  7.  
  8.     p = Me.txtPrint.Value
  9.  
  10.     'Close the report if it's already open (so the filtering is right.)
  11.     If CurrentProject.AllReports(strcDoc).IsLoaded Then
  12.         DoCmd.Close acReport, strcDoc
  13.     End If
  14.  
  15.     'Open it filtered to the batch in the list box.
  16.     strWhere = "fkBatch = " & DMin("[fkBatch]", "qryToPrint")
  17.     DoCmd.OpenReport strcDoc, acViewPreview, , strWhere
  18.  
  19. Exit_Handler:
  20.     Exit Sub
  21.  
  22. Err_Handler:
  23.     MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, ".cmdPrintBatch_Click"
  24.     Resume Exit_Handler
  25.  
  26. End Sub
Oct 23 '22 #1

✓ answered by NeoPa

Hi Birdlegs.

Putting this in simple terms you would do something like the following :
  1. Identify those items that you want selected for a print run of labels.
  2. Copy those items identified into a specially-designed temporary table used for the printing of the labels.
  3. You can allow incrementally adding items in with multiple batches if you choose or, if not, you can clear any existing records prior to this step. If you do the latter then make sure they are used to identify the records that have been printed if appropriate. That depends on the stage at which you require these to be flagged. See #2 below.
  4. When do you want the originals flagged as printed? If it's as soon as they're identified then ensure the data from this temporary table is used to update the originals to reflect that. If it is later, once they've actually been submitted to print, or even once you have humanly determined they have printed correctly, then apply this step later in the overall process where it makes sense.
  5. Whether you trigger the next step manually (Using a CommandButton for instance.) or logically (Once some records have been identified and made available.) doesn't matter too much, but proceed onto it one way or the other.
  6. Print off the items from within your temporary table to the printer.
  7. Once you have determined that all have been successfully printed then (optionally) update the original data (See #3.) then DELETE all the records from the temporary table.
If you follow this logic you should have a system that does what you want it to do.

3 11912
zmbd
5,501 Expert Mod 4TB
There are several ways I can think of how to do what you're after using several methods, such as an extra field in the table, tempvars-collection, another table (or two), etc...
Would you need a record of when the batches were printed?
Would you need to know which labels were in each batch?
Would you need to know the last time a record's label was printed?

If no to all of the questions then I would use a tempvars collection to hold the record numbers, and possibly a batching value, needed for the batches and a counter to handle printing each batch of labels the required number of times.

The complexity increases if you answer yes to any of the questions. The simplest would be a flag field in the table that is set when selected, a DAO.Recordset to filter those records out for printing using SQL-Top to return just the first 30 records, an inner loop to print the required number of copies, code to clear the flag on the returned records, and the outer-loop to fetch the next 30 records.

From there we're looking possibly a running table with batch IDs related to the record table and/or more tables to hold the history.

Also please consider changing this:
Expand|Select|Wrap|Line Numbers
  1. Set rs = Nothing
  2. Set db = Nothing
to this
Expand|Select|Wrap|Line Numbers
  1. If Not rs  Is Nothing Then
  2.      rs.close
  3.      Set rs  = Nothing
  4.   End if
  5. If Not db Is Nothing Then Set db = Nothing
If you open it close it first before releasing the object
If you set on object then release it - but check that it's been set first!
This will avoid memory leak, data corruption, and errors that seem to pop-up from nowhere.
(BTW: NEVER do db.close on the when using Set db = CurrentDb() - I did that by mistake in one of my early applications, took me ages to find the error!!)
Oct 23 '22 #2
birdlegs
2 2Bits
I have the table that holds batch numbers and the date and time batches were created. But no, I don't need to know when the labels were printed, just IF they were printed, which is what the ysnLabels field is for. Basically, I need to know, if the user wants to print three pages of labels, for example, how to select three batch numbers (I am guessing maybe a GROUP BY sql) and load only those batches to the rptLabels to print. Then after printing is successful (confirmed with message box) I need to check the ysnfield so they aren't printed again.
And thank you for the tips on .Close at the end. Very insightful and helpful!
Oct 23 '22 #3
NeoPa
32,556 Expert Mod 16PB
Hi Birdlegs.

Putting this in simple terms you would do something like the following :
  1. Identify those items that you want selected for a print run of labels.
  2. Copy those items identified into a specially-designed temporary table used for the printing of the labels.
  3. You can allow incrementally adding items in with multiple batches if you choose or, if not, you can clear any existing records prior to this step. If you do the latter then make sure they are used to identify the records that have been printed if appropriate. That depends on the stage at which you require these to be flagged. See #2 below.
  4. When do you want the originals flagged as printed? If it's as soon as they're identified then ensure the data from this temporary table is used to update the originals to reflect that. If it is later, once they've actually been submitted to print, or even once you have humanly determined they have printed correctly, then apply this step later in the overall process where it makes sense.
  5. Whether you trigger the next step manually (Using a CommandButton for instance.) or logically (Once some records have been identified and made available.) doesn't matter too much, but proceed onto it one way or the other.
  6. Print off the items from within your temporary table to the printer.
  7. Once you have determined that all have been successfully printed then (optionally) update the original data (See #3.) then DELETE all the records from the temporary table.
If you follow this logic you should have a system that does what you want it to do.
Oct 23 '22 #4

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

Similar topics

1
by: Nick J | last post by:
We have LOADS of documents scanned to PDF format, stored in SQL tables. Allowing a client to browse our ASP driven site to select and view individual PDFs has been no problem. ("index" table is...
3
by: MHenry | last post by:
Hi, I have 30 separate Access reports to print to pdf files. Presently, I print these reports to Acrobat pdf files one report at a time. I am looking for some help, or a program or add-in...
1
by: Bob | last post by:
I have a query whose results contain the full path (i.e. c:\Images\xxx.tiff) to MUTI-PAGE (All two page) TIFF documents. I need to figure out how to BATCH print the tiff's using the path from...
1
by: Bob | last post by:
I have a query whose results contain the full path (i.e. c:\Images\xxx.tif) to MUTI-PAGE (All two page) TIF documents. I need to figure out how to BATCH print the tiff's using the path from the...
1
by: Mitchell Vincent | last post by:
I've had this trouble in every language I've tried for Windows. Apparently the problem is with the underlying controls or something.. When I loop through and use a hidden web gadget to load and...
3
by: orbitus | last post by:
I know that I am overcomplicating this. I have records that need to be printed. Lets say 536 records, some on two or more pages in the report. I want to print 30 records, then 30 more till the...
2
by: Gave | last post by:
Hello Everyone! I have a web application with a datagrid, so the user can check on a check box to send the printer an png file that correspond with each datagrid row. I need to print the images...
22
Missionary
by: Missionary | last post by:
I need to batch print reports. I've looked at past posts about batch printing, but I don't know visual basic, so I'll need some coaching. I have a report based on a parameter query. I have it...
3
by: nospam | last post by:
Hello, I have about two hundred individual RTF files to print from an XP host. Word 2000 doesn't seem to have this feature, so I'm looking for a way to print those RTF files from an ActivePython...
2
misscrf
by: misscrf | last post by:
I have a report which is grouped in header and footer. Each report has the page break set on the group footer. Any way I can write code or a macro or something that will print my report to a...
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...
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
jinu1996
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...
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,...
0
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...

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.