Combobox and list box selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tara99
    New Member
    • Oct 2006
    • 106

    Combobox and list box selection

    I have combo box which displays col1 from a table1, I have a button "OK" next to it.
    I also have a listbox which I want it to displays other information (col2) from table1 for a particular records.
    Note: table one has two column only, both are the primary keys (there are duplicate values).

    questions are:
    1- How can I make the OK button to displays records in the list box for the selected item from combobox?
    2- How can I make the List box to diplay nothing when I open the database (default to "")?
    3- Is there a way to hide the list box, once the user make a selection form combo box and hit the OK button than the list box appear with the relavent records?

    Any input is valued
    thanks
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32634

    #2
    1. Add code to change the 'ControlSorce' property.
    2. Set ListBox.ListInd ex to -1 (I think)
    3. Set the .Visible property - as in your other post.

    Comment

    • tara99
      New Member
      • Oct 2006
      • 106

      #3
      Originally posted by NeoPa
      1. Add code to change the 'ControlSorce' property.
      2. Set ListBox.ListInd ex to -1 (I think)
      3. Set the .Visible property - as in your other post.
      NeoPa

      I need more clarification please.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32634

        #4
        How far have you got so far with your attempts Tara?

        Comment

        • tara99
          New Member
          • Oct 2006
          • 106

          #5
          Originally posted by NeoPa
          How far have you got so far with your attempts Tara?
          Well my combo box is working meaning it does show column one of table1.
          the list box that i have for diplaying the records for selected item from combo box is fine.

          I have folowwing code in the rowsource of my list box
          Code:
           SELECT CostCentres.CostCentre, CostCentres.CC_NAME FROM CostCentres INNER JOIN CostCentreSecurity ON CostCentres.CostCentre=CostCentreSecurity.CostCentre WHERE (((CostCentreSecurity.NetworkID)=forms!Form1!NetworkID));
          Notte: NetwprkID is the the name of my combobox

          When I open the form both the combo box and the list box is empty which is good.
          Then when I select an item from the combo box the list box doesn’t show anything unless I go change to design mode and come back to view mode then I am able to see information available for the item in list box.

          What I want is that when I hit the button it show the details in the list box, it doesn’t do that at the moment.

          I hope it is clear
          thanks

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Add one line of code to after update event of combobox

            Me.ListboxName. Requery


            Originally posted by tara99
            Well my combo box is working meaning it does show column one of table1.
            the list box that i have for diplaying the records for selected item from combo box is fine.

            I have folowwing code in the rowsource of my list box
            Code:
             SELECT CostCentres.CostCentre, CostCentres.CC_NAME FROM CostCentres INNER JOIN CostCentreSecurity ON CostCentres.CostCentre=CostCentreSecurity.CostCentre WHERE (((CostCentreSecurity.NetworkID)=forms!Form1!NetworkID));
            Notte: NetwprkID is the the name of my combobox

            When I open the form both the combo box and the list box is empty which is good.
            Then when I select an item from the combo box the list box doesn’t show anything unless I go change to design mode and come back to view mode then I am able to see information available for the item in list box.

            What I want is that when I hit the button it show the details in the list box, it doesn’t do that at the moment.

            I hope it is clear
            thanks

            Comment

            • tara99
              New Member
              • Oct 2006
              • 106

              #7
              Originally posted by mmccarthy
              Add one line of code to after update event of combobox

              Me.ListboxName. Requery
              Thanks Mary
              It work for the combox now,
              How about the button.
              I want it to work when I hit the button???

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #8
                Originally posted by tara99
                Thanks Mary
                It work for the combox now,
                How about the button.
                I want it to work when I hit the button???
                Have you tried putting the same line of code in the command button click event?

                Comment

                • tara99
                  New Member
                  • Oct 2006
                  • 106

                  #9
                  Originally posted by mmccarthy
                  Have you tried putting the same line of code in the command button click event?
                  Yes I did and it worked
                  I put
                  Code:
                  Private Sub FIND_Click()
                  AvailabeCC.Requery
                  End Sub
                  one more thing
                  when I change the selection before hitting the button, how can I make the listbox to don't show anything??

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32634

                    #10
                    Tara,

                    I'm glad you're making progress here.

                    Your point number two - It sounds like you may want either to have a ListBox showing no items at all to select from or show or to set the combobox to have no item selected.
                    If the former, then (we'll call your ListBox lstThis) :
                    Code:
                    lstThis.RowSource=""
                    If the latter, then (We'll call your ComboBox cboThis) :

                    Well...
                    It seems I don't know :(
                    I tried to find it in my help but it has bugs I'm afraid (Access 2003 seems lots worse than previous versions or it's just mucked up on my home PC :( )
                    I hope someone else has found a technique (I'm sure I've done it before but I can't find it atm - I'm afraid).

                    Comment

                    • MMcCarthy
                      Recognized Expert MVP
                      • Aug 2006
                      • 14387

                      #11
                      Originally posted by NeoPa
                      Tara,

                      I'm glad you're making progress here.

                      Your point number two - It sounds like you may want either to have a ListBox showing no items at all to select from or show or to set the combobox to have no item selected.
                      If the former, then (we'll call your ListBox lstThis) :
                      Code:
                      lstThis.RowSource=""
                      If the latter, then (We'll call your ComboBox cboThis) :

                      Well...
                      It seems I don't know :(
                      I tried to find it in my help but it has bugs I'm afraid (Access 2003 seems lots worse than previous versions or it's just mucked up on my home PC :( )
                      I hope someone else has found a technique (I'm sure I've done it before but I can't find it atm - I'm afraid).
                      Code:
                      lstThis = Null
                      should work

                      Comment

                      • tara99
                        New Member
                        • Oct 2006
                        • 106

                        #12
                        Originally posted by NeoPa
                        Tara,

                        I'm glad you're making progress here.

                        Your point number two - It sounds like you may want either to have a ListBox showing no items at all to select from or show or to set the combobox to have no item selected.
                        If the former, then (we'll call your ListBox lstThis) :
                        Code:
                        lstThis.RowSource=""
                        If the latter, then (We'll call your ComboBox cboThis) :

                        Well...
                        It seems I don't know :(
                        I tried to find it in my help but it has bugs I'm afraid (Access 2003 seems lots worse than previous versions or it's just mucked up on my home PC :( )
                        I hope someone else has found a technique (I'm sure I've done it before but I can't find it atm - I'm afraid).
                        Hi NeoPa
                        If you are talking about the (2- How can I make the List box to diplay nothing when I open the database (default to "")?
                        ) point2, I believe it is fine, I havn't write any code for it and yet it works meaning that when I open the form both the list and combo box is blank.
                        Point 1 is also working thanks to mary.

                        Now the problem that I have now is that when I want to change the selection from the combo box before hitting the button I want the list box to go blank.
                        the other question I have is
                        3- Is there a way to hide the list box, once the user make a selection form combo box and hit the OK button than the list box appear with the relavent records?

                        Thanks

                        Comment

                        • MMcCarthy
                          Recognized Expert MVP
                          • Aug 2006
                          • 14387

                          #13
                          To make the listbox go blank

                          Code:
                          Me.ListName.RowSource = ""
                          Try to work out where to put it based on previous instructions

                          To make the listbox invisible

                          Code:
                          Me.ListName.Visible = False
                          Remember to make it visible again in the Form Current, From Open or maybe Form Load event.

                          Test these commands out until you figure out where to use them. You'll learn more by doing it yourself.

                          Mary



                          Originally posted by tara99
                          Hi NeoPa
                          If you are talking about the (2- How can I make the List box to diplay nothing when I open the database (default to "")?
                          ) point2, I believe it is fine, I havn't write any code for it and yet it works meaning that when I open the form both the list and combo box is blank.
                          Point 1 is also working thanks to mary.

                          Now the problem that I have now is that when I want to change the selection from the combo box before hitting the button I want the list box to go blank.
                          the other question I have is
                          3- Is there a way to hide the list box, once the user make a selection form combo box and hit the OK button than the list box appear with the relavent records?

                          Thanks

                          Comment

                          Working...