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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jharp
    New Member
    • Aug 2009
    • 5

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

    Ok, so im really new to access and programing in general, what i am doing is building a inventory(somet hing 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 :)
  • ezechiel
    New Member
    • Jul 2009
    • 53

    #2
    (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_AfterU pdate -> 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 ;)

    Comment

    • Jharp
      New Member
      • Aug 2009
      • 5

      #3
      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 =/
      Last edited by Jharp; Aug 13 '09, 08:20 AM. Reason: clarity

      Comment

      • ezechiel
        New Member
        • Jul 2009
        • 53

        #4
        hi,

        this is the thread i talked about:


        This is the code ChipR gave me:
        Code:
        Private Sub cmbManufacturerFilter_AfterUpdate()
            Me.Filter = "Manufacturer = '" & cmbManufacturerFilter & "'"
            Me.FilterOn = True
        End Sub
        So maybe you should use something like this for your popped up form:
        Code:
        Private Sub Form_Current()
            Me.Filter = "Manufacturer = '" & previousform.cmbInventory & "'"
            Me.FilterOn = True
        End Sub
        You replace manufacturer with the value you want.
        Allthough, I'm not quite sure of the syntax of "form.objec t" I' m a noob too.

        Comment

        • ChipR
          Recognized Expert Top Contributor
          • Jul 2008
          • 1289

          #5
          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:
          Code:
          Private Sub cmbItemNumber_AfterUpdate() 
              Dim strWhereCondition as String
              strWhereCondition = "[ItemNumber] = " & cmbItemNumber
              DoCmd.OpenForm "frmViewRecords", , , strWhereCondition 
          End Sub

          Comment

          • Jharp
            New Member
            • Aug 2009
            • 5

            #6
            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

            Comment

            • Jharp
              New Member
              • Aug 2009
              • 5

              #7
              i cant get it to work, heres what i have ill try to explain alittle how i have it setup
              Private Sub Combo41_AfterUp date()
              Dim strWhereConditi on As String
              strWhereConditi on = "[Combo41] = " & Combo41
              DoCmd.OpenForm "stock1", , , strWhereConditi on
              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

              Comment

              • ChipR
                Recognized Expert Top Contributor
                • Jul 2008
                • 1289

                #8
                Your strWhereConditi on needs to be in the form:
                [tableFieldName] = value
                So, it looks like it should be:
                Code:
                strWhereCondition = "[old id] = " & Combo41

                Comment

                • Jharp
                  New Member
                  • Aug 2009
                  • 5

                  #9
                  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 :)

                  Comment

                  Working...