S
Simon Glencross
Help or ideas needed please....
I have a multi select listbox where the user selects different catalogue
types and they click a command button which send the subscribers details to
labels which they then print off. This all works great BUT now they want to
be able to continue selecting the individual catalogue type but also print
them by catcost i.e. paid, trail or comp.
Here is the code which I am currently using, I was thinking about maybe
adding another list box with the cat costs in but I am unsure of how to
incorporate this in to the current setup. Any help would be much appreciated
Si
Private Sub Command14_Click()
' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("Newquery16")
' Loop through the selected items in the list box and build a text string
For Each varItem In Me!List8.ItemsSelected
strCriteria = strCriteria & ",'" & Me!List8.ItemData(varItem) & "'"
Next varItem
' Check that user selected something
If Len(strCriteria) = 0 Then
MsgBox "You did not make a selection from the Labels list" _
, vbExclamation, "No Labels Found!"
Exit Sub
End If
' Remove the leading comma from the string
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
' Build the new SQL statement incorporating the string
strSQL = "SELECT DISTINCT tblSubscribers.Title, tblSubscribers.Forename, "
& _
"tblSubscribers.Surname, tblSubscribers.Company, " & _
"tblSubscribers.Address, " & _
"tblSubscribers.City, tblSubscribers.[Country/Region], " & _
"tblSubscribers.PostalCode " & _
"FROM tblSubscribers INNER JOIN tblsubscriptions ON " & _
"tblSubscribers.MailingListID = tblsubscriptions.MailingListID " & _
"WHERE (((tblsubscriptions.Cattypes) In (" & strCriteria & ")) AND
((tblsubscriptions.Catcost)='Paid' Or (tblsubscriptions.Catcost)='Free' Or
(tblsubscriptions.Catcost)='Trial')) " & _
"ORDER BY tblsubscribers.surname; "
Debug.Print strSQL
' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Open the query
DoCmd.OpenReport "Labels", acViewPreview
' Empty the memory
Set db = Nothing
Set qdf = Nothing
End Sub
I have a multi select listbox where the user selects different catalogue
types and they click a command button which send the subscribers details to
labels which they then print off. This all works great BUT now they want to
be able to continue selecting the individual catalogue type but also print
them by catcost i.e. paid, trail or comp.
Here is the code which I am currently using, I was thinking about maybe
adding another list box with the cat costs in but I am unsure of how to
incorporate this in to the current setup. Any help would be much appreciated
Si
Private Sub Command14_Click()
' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("Newquery16")
' Loop through the selected items in the list box and build a text string
For Each varItem In Me!List8.ItemsSelected
strCriteria = strCriteria & ",'" & Me!List8.ItemData(varItem) & "'"
Next varItem
' Check that user selected something
If Len(strCriteria) = 0 Then
MsgBox "You did not make a selection from the Labels list" _
, vbExclamation, "No Labels Found!"
Exit Sub
End If
' Remove the leading comma from the string
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
' Build the new SQL statement incorporating the string
strSQL = "SELECT DISTINCT tblSubscribers.Title, tblSubscribers.Forename, "
& _
"tblSubscribers.Surname, tblSubscribers.Company, " & _
"tblSubscribers.Address, " & _
"tblSubscribers.City, tblSubscribers.[Country/Region], " & _
"tblSubscribers.PostalCode " & _
"FROM tblSubscribers INNER JOIN tblsubscriptions ON " & _
"tblSubscribers.MailingListID = tblsubscriptions.MailingListID " & _
"WHERE (((tblsubscriptions.Cattypes) In (" & strCriteria & ")) AND
((tblsubscriptions.Catcost)='Paid' Or (tblsubscriptions.Catcost)='Free' Or
(tblsubscriptions.Catcost)='Trial')) " & _
"ORDER BY tblsubscribers.surname; "
Debug.Print strSQL
' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Open the query
DoCmd.OpenReport "Labels", acViewPreview
' Empty the memory
Set db = Nothing
Set qdf = Nothing
End Sub