joeserrone
The cat of the cul-de-sac
- Local time
- , 21:05
- Joined
- Dec 17, 2006
- Messages
- 164
I am using a multi-select list box to pass various search parameters to a query. The code below is working great but in the IF statement at the end of my code I wanted to do the following:
Instead of the user getting a message and having them select at least one item from the list box I wanted to display all the records. The SQL query that gets the results from the hidden text box that passes the criteria is listed below my code. I'm not sure if I can do this via code or modifying my SQL Query.
......VBA Code..................................
Dim lngLoop As Long
Dim strIDs As String
strQuote = Chr$(34)
If ListCategoryEdit.ItemsSelected.Count > 0 Then
strIDs = ""
For lngLoop = 0 To ListCategoryEdit.ItemsSelected.Count - 1
strIDs = strIDs & strQuote & ListCategoryEdit.ItemData(ListCategoryEdit.ItemsSelected(lngLoop)) & strQuote & " OR "
Next lngLoop
strIDs = Left(strIDs, Len(strIDs) - 4)
txtQueryCriteria = strIDs
Forms![EditEntryForm].Requery
DoCmd.OpenForm "EditEntryForm"
'DoCmd.OpenQuery "EditQuery"
Else
txtQueryCriteria = ""
MsgBox "You must select at least one Task from the Task Selection Box!", vbExclamation
End If
.....SQL Statement..................................
SELECT Assignments.Date, Assignments.Name, Assignments.Assignment, Assignments.[Start Time], Assignments.[End Time], Assignments.Items, Assignments.Notes
FROM Assignments
WHERE (((Assignments.Date) Between [Forms]![AdminWelcomeForm]![Start_Date_Edit] And [Forms]![AdminWelcomeForm]![End_Date_Edit]) AND ((Assignments.Name)=IIf([Forms]![AdminWelcomeForm]![EmployeeSelectorGrp]=1,[Name],[Forms]![AdminWelcomeForm]![NameSelectorEdit])) AND (([Forms]![AdminWelcomeForm]![txtQueryCriteria]) Like "*" & [Assignment] & "*"));
Instead of the user getting a message and having them select at least one item from the list box I wanted to display all the records. The SQL query that gets the results from the hidden text box that passes the criteria is listed below my code. I'm not sure if I can do this via code or modifying my SQL Query.
......VBA Code..................................
Dim lngLoop As Long
Dim strIDs As String
strQuote = Chr$(34)
If ListCategoryEdit.ItemsSelected.Count > 0 Then
strIDs = ""
For lngLoop = 0 To ListCategoryEdit.ItemsSelected.Count - 1
strIDs = strIDs & strQuote & ListCategoryEdit.ItemData(ListCategoryEdit.ItemsSelected(lngLoop)) & strQuote & " OR "
Next lngLoop
strIDs = Left(strIDs, Len(strIDs) - 4)
txtQueryCriteria = strIDs
Forms![EditEntryForm].Requery
DoCmd.OpenForm "EditEntryForm"
'DoCmd.OpenQuery "EditQuery"
Else
txtQueryCriteria = ""
MsgBox "You must select at least one Task from the Task Selection Box!", vbExclamation
End If
.....SQL Statement..................................
SELECT Assignments.Date, Assignments.Name, Assignments.Assignment, Assignments.[Start Time], Assignments.[End Time], Assignments.Items, Assignments.Notes
FROM Assignments
WHERE (((Assignments.Date) Between [Forms]![AdminWelcomeForm]![Start_Date_Edit] And [Forms]![AdminWelcomeForm]![End_Date_Edit]) AND ((Assignments.Name)=IIf([Forms]![AdminWelcomeForm]![EmployeeSelectorGrp]=1,[Name],[Forms]![AdminWelcomeForm]![NameSelectorEdit])) AND (([Forms]![AdminWelcomeForm]![txtQueryCriteria]) Like "*" & [Assignment] & "*"));