By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,661 Members | 1,808 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,661 IT Pros & Developers. It's quick & easy.

How do I open a filtered form based on a selection in a Combobox?

P: 5
Ok, so im really new to access and programing in general, what i am doing is building a inventory(something simple),

the way ive got it set up now is, my entire inventory is in a combo box, and what i want to be able to do is select an item from the combo box and have it open a window(form?).

ok so i got this far, i have it Onclick open a newform, and that works fine but it returns everything in inventory, so what i need it to do is filter the new form based on what i click in the combo box, and for the life of me cant figure it out =(

I know this problem cant be hard im just to dumb to figure it out please help and thank you i hope i was clear enough :)
Aug 13 '09 #1
Share this Question
Share on Google+
8 Replies

P: 53
(if opening a new form window is not a must for you, you acn look at the thread "limit browseable records by combobox).. There, you put a combobox in the header of the form and it will filter the content of the form..

So if you really want to open a new form, you could do exactly the same.
combobox_AfterUpdate -> open new form

In the new form, use the filter code (like in the mentioned thread) with the value of the combobox after update. I think this is the easiest way.. I'm sure ChipR will show up and give you more details if you didn't quite understand ;)
Aug 13 '09 #2

P: 5
well what i wanted to do was use the combobox for a generic list, then if you click on a item in the combobox it opens up a new form with all the detailed info on that item,

i have the combo box set up and when i click it opens up the form i want, but i cant get it to filter the new form based on what i click, it just lists every item =/
Aug 13 '09 #3

P: 53

this is the thread i talked about:

This is the code ChipR gave me:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbManufacturerFilter_AfterUpdate()
  2.     Me.Filter = "Manufacturer = '" & cmbManufacturerFilter & "'"
  3.     Me.FilterOn = True
  4. End Sub
So maybe you should use something like this for your popped up form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Me.Filter = "Manufacturer = '" & previousform.cmbInventory & "'"
  3.     Me.FilterOn = True
  4. End Sub
You replace manufacturer with the value you want.
Allthough, I'm not quite sure of the syntax of "form.object" I' m a noob too.
Aug 13 '09 #4

Expert 100+
P: 1,287
That code will filter the form you are on, but in this case it would be better to filter the form being opened with the WhereCondition argument of the DoCmd.OpenForm. For example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbItemNumber_AfterUpdate() 
  2.     Dim strWhereCondition as String
  3.     strWhereCondition = "[ItemNumber] = " & cmbItemNumber
  4.     DoCmd.OpenForm "frmViewRecords", , , strWhereCondition 
  5. End Sub 
Aug 13 '09 #5

P: 5
ah thats looking more like, unfortunately i dont have the project with me to try it out, but that looks like what i was shooting for
Aug 14 '09 #6

P: 5
i cant get it to work, heres what i have ill try to explain alittle how i have it setup
Private Sub Combo41_AfterUpdate()
Dim strWhereCondition As String
strWhereCondition = "[Combo41] = " & Combo41
DoCmd.OpenForm "stock1", , , strWhereCondition
End Sub

ok i have a table named "stock" it is my master list in my inventory its primary key is "old id" i then have a combo box named "combo41" which is based on table "stock" so it has everything.
I also made a Form named "Stocksub" which is formatted to show every item on its own page with more details
so what i would like is when i select an item out of the "combo41" i would like it to open "stocksub" and only display(or go to the right page) the item that is selected in "combo41"
i hope this makes some sense, and if you have a better way to set it up let me know :) thanks soo much for your help
Aug 17 '09 #7

Expert 100+
P: 1,287
Your strWhereCondition needs to be in the form:
[tableFieldName] = value
So, it looks like it should be:
Expand|Select|Wrap|Line Numbers
  1. strWhereCondition = "[old id] = " & Combo41
Aug 17 '09 #8

P: 5
YES finally thanks soo much, i knew it was simple, i just needed someone who knew what they were doing, ty sir and have a great day :)
Aug 18 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.