Combo box

knice11

Registered User.
Local time
Today, 08:00
Joined
Jun 14, 2011
Messages
20
Hello. I have a combo box on my form in access 2007. It only has 3 choices in the combo box. How can I get the button below the combo box to only show the records that are listed in the combo box at that time. Like if F41 is selected, I only would like to see all the records that go to F41 at that time and so on. Any help would be greatly appreciated.
 
Do you mean filter the records to only those that relate to the item selected in the combobox?

If so there are plenty of examples of people doing that on this forum.
(just google:
filter form combobox site:access-programmers.co.uk
)

To answer your specific case we'd need more information about the form, it's recordsource and what field(s) the combobox relates to.
 
Yeah I need to filter it and just show certain records as the ones that would be selected from the combobox at certain time. Like F41 show all and only F41 records.
 

Attachments

I forgot to mention that there is two buttons on the form. One shows all the records listed in the zip file and the other I need to show only the records from the combo box.
 
Assuming that WH Query is the recordsource of the Warehouse form then you'd need some code in the combobox's After Update event (right click the combo box, select properties, in the properties box go to the events tab, find After Update and select Event Procedure and the click ... next to it - in the sub it creates for that). I don't know the name of the combobox but I'm going to call it cboFilter for the example:

Code:
Private Sub cboFilter_AfterUpdate()
    Me.Filter = IIf(Nz(cboFilter.Value,"") <> "","[WH #] = """ & cboFilter.Value & """","")
    Me.FilterOn = (Nz(cboFilter.Value,"") <> "")
End Sub

Change all occurances of cboFilter to the name of your combobox.
 
Last edited:
Thank you. I have just one more quick question. When I input this code, will it work with the second button. I know I would need to imput it into a macro. Which action event would I use to make sure all of it runs smoothly or do I need to put it in a macros for the button?
 
The AfterUpdate method will mean it happens as soon as anyone selects an item or clears the text in the combobox.

To make it happen after button clicks then put the code in the click event of the first button and put slightly different code in the click event of the second button (I'm just going to call them button1 and button2 for sake of this demo):

Code:
Private Sub button1_Click()
    Me.Filter = IIf(Nz(cboFilter.Value,"") <> "","[WH #] = """ & cboFilter.Value & """","")
    Me.FilterOn = (Nz(cboFilter.Value,"") <> "")
End Sub
 
Private Sub button2_Click()
    cboFilter.Value = Null
    Me.Filter = ""    
    Me.FilterOn = False
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom