Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check box Option Group 1

Status
Not open for further replies.

homless

Technical User
Oct 26, 2009
10
US
I have an Access form that has 4 check boxes. I have 4 queries for each check box and a combo drop down list that displays products that are in my table tblproduct. The check boxes are named as follows:

InStockQ
OutOfStockQ
DiscontinuedItemsQ
All Products
The frame name for the grouped check box is called grpBox.
Now what I am looking for is a way to be able to select each checkbox and the query corresponding to the check box displays the products in the combo box. For example, if I check the OutOfStockQ checkbox, I want only the products that are Out of stock to populate the combo box. Is there a way a simple way to do this? I tried using the toggle buttons but I could only get two options to work that is why I switched to check box. I am open to whichever is easier.
Much thanks,
Liz
 
How about sharing something about the table structure(s) of the Row Source of the combo box?

What are the values of each of the check boxes? Can we assume this is an option frame where only one box can be checked at a time?


Duane
Hook'D on Access
MS Access MVP
 

If your option group is set up properly, each option button (or check box) will have a value (0-3 or 1-4).
I'd use a SELECT CASE statement to determine which query to run. Something like this maybe?
Code:
SELECT CASE grpBox
   Case 1:
      'code to run 1st query and anything else needed
   Case 2:
      'code to run 2nd query
   Case 3:
      'code to run 3rd query
   Case 4:
      'code to run 4th query
End Select
Notice that the select statement is for the option group, not an individual button or check box.


Randy
 
Thank you [2thumbsup] This is what I did and it appears to be working. Is there something else that I should add? Can I add Me.Requery after each case statement? What do you think? I want to be able to see new records that are added to the product table.

Private Sub grpBox_Click()
Select Case grpBox
Case 1
Me.Text2.RowSource = "SELECT qryInStock.ProductName FROM qryInStock
Case 2
Me.Text2.RowSource = "SELECT qryOutOfStock.ProductName FROM qryOutOfStock

Case 3
Me.Text2.RowSource = "SELECT qryDiscontinued.ProductName FROM qryDiscontinued
Case 4
Me.Text2.RowSource = "SELECT qryAllProducts.ProductName FROM qryAllProducts

End Select
End Sub
 
Left out the quotation(") marks at the end of the queries on the last thread.
Case 1
Me.Text2.RowSource = "SELECT qryInStock.ProductName" FROM qryInStock
Case 2
Me.Text2.RowSource = "SELECT qryOutOfStock.ProductName FROM qryOutOfStock"
Case 3
Me.Text2.RowSource = "SELECT qryDiscontinued.ProductName" FROM qryDiscontinued"
Case 4
Me.Text2.RowSource = "SELECT qryAllProducts.ProductName FROM qryAllProducts
 

Why add the same code after every case statement?
Simply add it AFTER the End Select.
Code:
...
End Select
Me.Requery
End Sub
However, I don't think the requery is going to be necessary.
The DISPLAYED value won't update, so you might want to add some code to update the displayed value.


Randy
 
I'm not sure why you have separate queries. Also, leaving the name of a combo box as Text2 is a sin ;-).

Code:
Dim strWhere as String
Select grpBox
   Case 1  ' in stock
       strWhere = "[StockStatus] = 'InStock' "
   Case 2  ' out of stock
       strWhere = "[StockStatus] = 'OutStock' "
   Case 3  ' Discontinued
       strWhere = "[StockStatus] = 'Discon' "
   Case 4  ' All
     strWhere = "[StockStatus] = [StockStatus] "
End Select
Me.cboProducts.RowSource = "SELECT fieldA, fieldB FROM qryProducts WHERE " & strWhere & " ORDER BY FieldB;"

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top