A family of Microsoft relational database management systems designed for ease of use.
I recommend referring to the AI-generated answer, as it outlines an alternative approach that may help simplify the item selection process by using a single query with optional criteria.
Based on your description, I also tested this approach in my Access environment using sample data. If you have not already implemented a similar setup, you can try the following steps:
Step 1: Create the search query
Go to Create > Query Design, close the Add Tables dialog, and switch to SQL View. Enter the SQL below and save the query as qryItemSearch.
SELECT N.ItemID, N.ItemName, N.ItemDescription, PC.PrimaryCategory, SC.SubCategory, C.ClassName, CO.ColorName, S.SizeName, P.PackageName
FROM (((((NewItems AS N LEFT JOIN PrimaryCategories AS PC ON N.PrimaryCategoryID = PC.PCId) LEFT JOIN SubCategories AS SC ON N.SubCategoryID = SC.SCId) LEFT JOIN Classes AS C ON N.ClassID = C.ClassId) LEFT JOIN Colors AS CO ON N.ColorID = CO.ColorId) LEFT JOIN Sizes AS S ON N.SizeID = S.SizeId) LEFT JOIN Packages AS P ON N.PackageID = P.PackageId
WHERE (Forms!frmItemFinder!cboPrimaryCategory Is Null
OR N.PrimaryCategoryID = Forms!frmItemFinder!cboPrimaryCategory)
AND (Forms!frmItemFinder!cboSubCategory Is Null
OR N.SubCategoryID = Forms!frmItemFinder!cboSubCategory)
AND (Forms!frmItemFinder!cboClass Is Null
OR N.ClassID = Forms!frmItemFinder!cboClass)
AND (Forms!frmItemFinder!cboColor Is Null
OR N.ColorID = Forms!frmItemFinder!cboColor)
AND (Forms!frmItemFinder!cboSize Is Null
OR N.SizeID = Forms!frmItemFinder!cboSize)
AND (Forms!frmItemFinder!cboPackage Is Null
OR N.PackageID = Forms!frmItemFinder!cboPackage)
ORDER BY N.ItemName;
This example assumes that NewItems stores the attribute IDs and that the lookup tables contain the corresponding names. Adjust the table and field names to match your database.
Step 2: Create the frmItemFinder search form
1.Select Create > Form Design.
2.Save the form as frmItemFinder.
3.Add six Combo Box controls, one Command Button, one Label, and one Subform/Subreport control.
Arrange the controls as needed. For each combo box, set the following properties in the Property Sheet:
-Row Source Type: Table/Query
-Bound Column: 1
-Column Count: 2
-Column Widths: 0";2"
-Control Source: leave blank
The first column contains the lookup ID, while the second displays the readable name.
Set each combo box's Row Source to the corresponding SQL below.
-cboPrimaryCategory
SELECT PCId, PrimaryCategory FROM PrimaryCategories ORDER BY PrimaryCategory;
-cboSubCategory
SELECT SCId, SubCategory FROM SubCategories ORDER BY SubCategory;
-cboClass
SELECT ClassId, ClassName FROM Classes ORDER BY ClassName;
-cboColor
SELECT ColorId, ColorName FROM Colors ORDER BY ColorName;
-cboSize
SELECT SizeId, SizeName FROM Sizes ORDER BY SizeName;
-cboPackage
SELECT PackageId, PackageName FROM Packages ORDER BY PackageName;
For each combo box, set the After Update property to [Event Procedure].
Next, configure the other controls:
-cmdClear button
+Name: cmdClear
+Caption: Clear Filters
+On Click: [Event Procedure]
-lblStatus label
+Name: lblStatus
-subItemResults subform control
Name: subItemResults
You can link the results form in Step 3.
Step 3: Create the results subform
1.Select Create > Form Design.
2.Set the form's Record Source to qryItemSearch.
3.Save the form as sfrmItemResults.
4.Set Default View to Datasheet.
Ensure the following fields are available in the results:
-ItemID
-ItemName
-ItemDescription
-PrimaryCategory
-SubCategory
-ClassName
-ColorName
-SizeName
-PackageName
5.Return to frmItemFinder in Design View.
-Select the subform control named subItemResults.
-Set its Source Object to Form.sfrmItemResults.
-Leave Link Master Fields and Link Child Fields blank, because the query applies the filters directly from the combo boxes.
-Save the form.
Step 4: Add the VBA code
Open frmItemFinder in Design View, select the form, and open its code module. Save the code and close the VBA editor.
Option Compare Database
Option Explicit
Private Sub ApplyItemFilter()
On Error GoTo ErrHandler
Dim rs As DAO.Recordset
Me.subItemResults.Form.Requery
Set rs = Me.subItemResults.Form.RecordsetClone
If rs.BOF And rs.EOF Then
Me.lblStatus.Caption = _
"No matching items found. Try changing your selections."
Else
rs.MoveLast
Me.lblStatus.Caption = _
"Matching items: " & rs.RecordCount
End If
rs.Close
Set rs = Nothing
Exit Sub
ErrHandler:
MsgBox "Could not refresh results. Check the control names.", _
vbExclamation
End Sub
Private Sub cboPrimaryCategory_AfterUpdate()
ApplyItemFilter
End Sub
Private Sub cboSubCategory_AfterUpdate()
ApplyItemFilter
End Sub
Private Sub cboClass_AfterUpdate()
ApplyItemFilter
End Sub
Private Sub cboColor_AfterUpdate()
ApplyItemFilter
End Sub
Private Sub cboSize_AfterUpdate()
ApplyItemFilter
End Sub
Private Sub cboPackage_AfterUpdate()
ApplyItemFilter
End Sub
Private Sub cmdClear_Click()
Me.cboPrimaryCategory = Null
Me.cboSubCategory = Null
Me.cboClass = Null
Me.cboColor = Null
Me.cboSize = Null
Me.cboPackage = Null
ApplyItemFilter
End Sub
Private Sub Detail_Click()
End Sub
Step 5: Test the form
Open frmItemFinder, apply filters, verify the results, and click Clear Filters to reset.
Please adjust the table names, field names, and form/control names in the query and VBA code to match your database structure. The exact implementation may vary depending on your existing tables and relationships.
I hope this gives you a useful starting point.