Hi Paul,
Here is the code that I'm using and the sql query that i'm using to get the data. As suggested I added the "LabelCopies" table to the query
and included the copies requested clause to the query. This works well for my needs. However, what i'd like to have is a unique documet number for
each label that prints. The number does not need to be stored anywhere, just printed out on the label.
Private Sub cmdPrintPreview_Click()
Dim vItm As Variant
Dim stWhat As String
Dim stCriteria As String
Dim stSQL As String
Dim loqd As QueryDef
stWhat = "": stCriteria = ","
For Each vItm In Me!lstSaless.ItemsSelected
stWhat = stWhat & Me!lstSales.ItemData(vItm)
stWhat = stWhat & stCriteria
Next vItm
Me!txtCriteria = CStr(Left$(stWhat, Len(stWhat) - Len(stCriteria)))
Set loqd = CurrentDb.QueryDefs("qrySelect"

stSQL = "SELECT * "
stSQL = stSQL & "FROM qrySelect, LabelCopies WHERE dwaccountid"
stSQL = stSQL & " IN (" & Me!txtCriteria & "

and copiesrequested <= Copies"
loqd.SQL = stSQL
loqd.Close
DoCmd.OpenReport "rptSalesLabel", acViewPreview
'Me.Form.Visible = False
End Sub
Here is the SQL query I'm using
SELECT *
FROM qrySales, LabelCopies
WHERE dwaccountid IN (7,9,13)and copiesrequested <= Copies;
As a by the by i read the posts that you pointed me to and, if i'm understanding them right, i think i came accross that problem on another project.
Just to recap, the poster wanted to print a label for a record based on the quantity of items on the record. Heres how i handled the problem.
Private Sub cmdPrintLabel_Click()
On Error GoTo Err_cmdPrintLabel_Click
Dim stdocname As String
Dim Check, Counter
Check = True: Counter = 0 ' Initialize variables.
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Print a label for each item?"
Style = vbYesNo + vbWarning + vbDefaultButton1 + vbSystemModal
Title = "Print all labels?"
Help = "DEMO.HLP"
Ctxt = 1000
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then
' this bit adds collection details to the job
szAccImportCode = CompanyId.Column(1)
AccCodeTxt = CompanyId.Column(1)
szAccName = CompanyId.Column(2)
szColAddrName = CompanyId.Column(2)
szColAddr1 = CompanyId.Column(3)
szColAddr2 = CompanyId.Column(4)
szColAddr3 = CompanyId.Column(5)
szColAddr4 = CompanyId.Column(6)
szColAddr5 = CompanyId.Column(7)
szColPostCode = CompanyId.Column(8)
szColTelephone = CompanyId.Column(9)
szCustomerPOD = NextNumberId.Column(1)
' this bit saves the record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'this bit prints the labels and loops around until the counter equals the qty.
If dwrQuantity > 0 Then
Do ' Outer loop.
Do While Counter < dwrQuantity ' Inner loop.
Counter = Counter + 1 ' Increment Counter.by 1
stdocname = "rptDespatchLabel"
' NOTE ** This does not work with print preview, you must send straight to printer.
DoCmd.OpenReport stdocname, acNormal
If Counter = dwrQuantity Then ' If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately
Else: End If
'this disables the exit option until save is pressed
Me!cmdExit.Enabled = False
Me!DeleteEntry.Enabled = True
Else
End If
Exit_cmdPrintLabel_Click:
Exit Sub
Err_cmdPrintLabel_Click:
MsgBox Err.Description
Resume Exit_cmdPrintLabel_Click
Hope I got the jist of the post right and am able to help someone with this in the future. As for my problem I hope that you can help.
Regards,
Noel.