MS ACCESS: Hide Specific Values from Combo box

Hello Team

Can you please advise how to hide specific values from a combobox list?

For example:  I have a main form which is used to either display previously created records or can be used to create new records.  When the form is loaded to display a history record, the combobox cboErrorCat displays, Error1, Error2, Error3, Error4 when selected. What I require is for the cboErrorCat to display only Error1 and Error2 when the form is loaded to create a new record.

Main Form is called frmPaymentError, combobox is named, cboErrorCat and the row source for the cboErrorCat combobox is called qryErrorCategories

Query SQL
SELECT tblErrorCategories.ErrorCategoryID AS Expr1, tblErrorCategories.ErrorCategory AS Expr2
FROM tblErrorCategories
WHERE (((tblErrorCategories.DateExpired)>Date()))
ORDER BY tblErrorCategories.Order;

Open in new window



Any assistance would be much appreciated.

Thanks in advance.
Dale JamesTherapistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
There are two basic ways to achieve this:

1. Load the combo with the values you want, either with a call back function or constructing a value list.

2. Adding criteria to the query it's based on or switching the row source to a different query, and then requerying.

 Typically one does #2, but you didn't say what conditions make the various entries possible, so #2 might not be doable.

 Explain a little more how the values are chosen under what conditions.

Jim.
Dale JamesTherapistAuthor Commented:
Hello Jim

Thanks for getting back to me.

The values for the combo list are obtained from a rowsource value list via the query qryErrorCategories.  This query consists of all the values that are seen when viewing historical records but when creating a new record only Error1 and Error2 list values (items) are to be viewable.

There is currently no filtering or criteria set in the query to limit the view of values.

Please let me know if you need more detail as am not sure if the above is addressing your question.

Ta

Dale
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Ah. now I got it.

I would construct another query that restricts the Error's to 1 and 2.   Then either in the GotFocus of the combo or the OnCurrent event, just do:

 If Me.NewRecord = True then
  Me.cboErrorCat.RowSource = "qryErrorCategories_Limited"
 Else
  Me.cboErrorCat.RowSource = "qryErrorCategories"
 End If
 
 Me.cboErrorCat.Requery

Jim.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

Gustav BrockCIOCommented:
You could set the count of records to be retrieved from your query:

Private Sub Form_Current()

    Const Sql       As String = "Select Top {0} * From qryErrorCategories"
    
    Dim RowSource   As String
    
    If Me.NewRecord Then
        ' Select two rows
        RowSource = Replace(Sql, "{0}", 2)
    Else
        RowSource = Replace(Sql, "{0}", 4)
    End If
    
    ' Only requery the combobox if needed.
    If Me!cboTest.RowSource <> RowSource Then
        Me!cboTest.RowSource = RowSource
    End If

End Sub

Open in new window

The combobox will update automatically when the rowsource is set.

Given the output, I'm not sure why your query is sorted by "Order". It should probably read:

SELECT tblErrorCategories.ErrorCategoryID AS Expr1, tblErrorCategories.ErrorCategory AS Expr2
FROM tblErrorCategories
WHERE (((tblErrorCategories.DateExpired)>Date()))
ORDER BY tblErrorCategories.ErrorCategory ;

Open in new window

Dale JamesTherapistAuthor Commented:
Thanks Jim and Gustav for your assistance.

Just working through the detail at the moment.  

Will feedback soon.

Ta

Dale
Dale JamesTherapistAuthor Commented:
Hello Jim and Gustav...

Just want to say thank you for your assistance regarding the this particular topic. Both responses provided the answer.

Thanks again.

Dale
Gustav BrockCIOCommented:
You are welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.