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:
I can print 1 Batch. How do I print x number of batches and then mark those batches as printed using the ysnLabels?
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:
Code:
Private Sub cmdBatch_Click() Dim db As DAO.Database Dim rs As DAO.Recordset Dim strSql As String Dim lngBatch As Long Dim i As Integer Dim mb As Integer m = Me.txtMaxBatch.Value If mb = 0 Then MsgBox "All labels have been batched." Else For i = 1 To mb Set db = CurrentDb() Set rs = db.OpenRecordset("tblBatch", dbOpenDynaset, dbAppendOnly) rs.AddNew rs!BatchCreated = Now() lngBatch = rs!pkBatch rs.Update rs.Close strSql = "UPDATE qryTop30 Set fkBatch = " & lngBatch & " WHERE ysnLabels = 0;" db.Execute strSql, dbFailOnError DoCmd.Requery qryTop30 Next i End If Exit_Handler: Set rs = Nothing Set db = Nothing Exit Sub Err_Handler: MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "cmdCreate_Click()" Resume Exit_Handler End Sub
Code:
Private Sub cmdPrint_Click() 'On Error GoTo Err_Handler Dim strWhere As String Const strcDoc = "rptLabels" Dim i As Integer Dim p As Integer p = Me.txtPrint.Value 'Close the report if it's already open (so the filtering is right.) If CurrentProject.AllReports(strcDoc).IsLoaded Then DoCmd.Close acReport, strcDoc End If 'Open it filtered to the batch in the list box. strWhere = "fkBatch = " & DMin("[fkBatch]", "qryToPrint") DoCmd.OpenReport strcDoc, acViewPreview, , strWhere Exit_Handler: Exit Sub Err_Handler: MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, ".cmdPrintBatch_Click" Resume Exit_Handler End Sub
Comment