List box using tables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chris vettese

    List box using tables

    I have a table called table1 that has a one to many relationship to
    table2. What I would like to do is have a form with two list boxes on
    it. The first list box will have a field from all of the records in
    table1. When the user clicks on one of the records, the second list
    box will show all of the records related to that from table2. Is this
    possible? How can it be done.

    Regards,
    Chris Vettese
  • Hegamyer

    #2
    Re: List box using tables

    Can you use a subform and have the 2nd list box in the subform?

    "chris vettese" <chrisvettese@y ahoo.com> wrote in message
    news:40002484.0 402191412.1c381 a3e@posting.goo gle.com...[color=blue]
    > I have a table called table1 that has a one to many relationship to
    > table2. What I would like to do is have a form with two list boxes on
    > it. The first list box will have a field from all of the records in
    > table1. When the user clicks on one of the records, the second list
    > box will show all of the records related to that from table2. Is this
    > possible? How can it be done.
    >
    > Regards,
    > Chris Vettese[/color]


    Comment

    • Peter Steimann[MVP Access]

      #3
      Re: List box using tables

      Chris

      "chris vettese" <chrisvettese@y ahoo.com> schrieb im Newsbeitrag
      news:40002484.0 402191412.1c381 a3e@posting.goo gle.com...[color=blue]
      > I have a table called table1 that has a one to many relationship to
      > table2. What I would like to do is have a form with two list boxes on
      > it. The first list box will have a field from all of the records in
      > table1. When the user clicks on one of the records, the second list
      > box will show all of the records related to that from table2. Is this
      > possible? How can it be done.
      >[/color]

      you can use the value of listbox1 as criteria for the rowsource of
      listbox2

      me.mylistbox2.r owsource = "select whatever from table2 where
      contentofthefie ld = " & me.mylistbox1.c olumn(0) or ...any
      column-number.

      Peter

      Comment

      • Mike Storr

        #4
        Re: List box using tables

        On 19 Feb 2004 14:12:58 -0800, chris vettese wrote:
        [color=blue]
        > I have a table called table1 that has a one to many relationship to
        > table2. What I would like to do is have a form with two list boxes on
        > it. The first list box will have a field from all of the records in
        > table1. When the user clicks on one of the records, the second list
        > box will show all of the records related to that from table2. Is this
        > possible? How can it be done.
        >
        > Regards,
        > Chris Vettese[/color]

        Without knowing what is in these tables I can only be general. Set the
        rowsource for the first listbox to aquery that returns all the results you
        want from table1. Make the bound column of this list box whichever field is
        the related one from table2.
        In the second list box set the rowsource to a query that returns all the
        fields you want "...WHERE (table2.FieldNa me = forms!FormName! Listbox1);"
        If necessary, use the AfterUpdate event of the first listbox to requery the
        second. this way each choice in the first, will cause the second to change
        its list.
        --
        Mike Storr

        Comment

        • chris vettese

          #5
          Re: List box using tables

          Mike,

          I tried your suggested solution and it didn't work. I also tried some
          of the other suggestions with out luck. Maybe if I give more details
          it will help.

          tblPartNumber has a 1 to many relationship with tblTicketNumber

          tblPartNumber has the following fields PartID (Auto Number),
          PartNumber (Number), Completed (Yes/No)
          I made a query from this table called qryPartNumber. The only
          criteria is that Completed = No

          tblTicketNumber has the following fields TicketID (Auto Number),
          TicketNumber (Number), Completed (Yes/No), PartID (Number)
          I made a query from this table called qryTicketNumber . The
          criteria is that Completed = No and PartID =
          [Forms]![frmPartNumber]![PartID]

          I created a form called frmPartNumber. On the form are 2 unbound list
          boxes. The first listbox has the Row Source as qryPartNumber. The
          second list box has the row source as qryTickeNumber. Both list boxes
          have column 1 (PartID) as the bound column. On the AfterUpdate Event
          for the 1st list box I have Me.Requery.

          When the form opens, the 1st list box lists all of the Part ID's from
          the query. The second list box shows all of the Part ID's for the
          first part number. If I click on the second part ID nothing changes
          in the second list box. I have 2 problems: 1 - The second list box
          does not update when I choose another part number (I'm not sure how to
          requery the qryTicketNumber in code. 2 - I want the part Number and
          Ticket Number to show up in the lists boxes, not the ID #'s

          Any additional help you can provide would be much appreciated.

          Best Regards,
          Chris Vettese






          Mike Storr <storrboy@sympa tico.ca> wrote in message news:<1nhnfqwve 4uf7$.1rp0i7cvs x5mb.dlg@40tude .net>...[color=blue]
          > On 19 Feb 2004 14:12:58 -0800, chris vettese wrote:
          >[color=green]
          > > I have a table called table1 that has a one to many relationship to
          > > table2. What I would like to do is have a form with two list boxes on
          > > it. The first list box will have a field from all of the records in
          > > table1. When the user clicks on one of the records, the second list
          > > box will show all of the records related to that from table2. Is this
          > > possible? How can it be done.
          > >
          > > Regards,
          > > Chris Vettese[/color]
          >
          > Without knowing what is in these tables I can only be general. Set the
          > rowsource for the first listbox to aquery that returns all the results you
          > want from table1. Make the bound column of this list box whichever field is
          > the related one from table2.
          > In the second list box set the rowsource to a query that returns all the
          > fields you want "...WHERE (table2.FieldNa me = forms!FormName! Listbox1);"
          > If necessary, use the AfterUpdate event of the first listbox to requery the
          > second. this way each choice in the first, will cause the second to change
          > its list.[/color]

          Comment

          • Mike Storr

            #6
            Re: List box using tables


            "chris vettese" <chrisvettese@y ahoo.com> wrote in message
            news:40002484.0 402201015.66e6f 3a2@posting.goo gle.com...[color=blue]
            > Mike,[/color]
            [color=blue]
            > I created a form called frmPartNumber. On the form are 2 unbound list
            > boxes. The first listbox has the Row Source as qryPartNumber. The
            > second list box has the row source as qryTickeNumber. Both list boxes
            > have column 1 (PartID) as the bound column.[/color]

            This likely means that the second listbox is not retaining the value you
            want. The bound column is what value the listbox will have when a row item
            is selected
            [color=blue]
            >On the AfterUpdate Event
            > for the 1st list box I have Me.Requery.[/color]

            Using Me.Requery will attempt to requery the form not the list box. Use
            Me!ListboxName. Requery
            [color=blue]
            >
            > When the form opens, the 1st list box lists all of the Part ID's from
            > the query. The second list box shows all of the Part ID's for the
            > first part number. If I click on the second part ID nothing changes
            > in the second list box. I have 2 problems: 1 - The second list box
            > does not update when I choose another part number (I'm not sure how to
            > requery the qryTicketNumber in code.[/color]

            See above note
            [color=blue]
            >2 - I want the part Number and Ticket Number to show up
            >in the lists boxes, not the ID #'s[/color]

            Then you'll need to adjust the ColumnWidths to show hide the needed
            columns from the query.

            [color=blue]
            > Mike Storr <storrboy@sympa tico.ca> wrote in message[/color]
            news:<1nhnfqwve 4uf7$.1rp0i7cvs x5mb.dlg@40tude .net>...[color=blue][color=green]
            > > On 19 Feb 2004 14:12:58 -0800, chris vettese wrote:
            > >[color=darkred]
            > > > I have a table called table1 that has a one to many relationship to
            > > > table2. What I would like to do is have a form with two list boxes on
            > > > it. The first list box will have a field from all of the records in
            > > > table1. When the user clicks on one of the records, the second list
            > > > box will show all of the records related to that from table2. Is this
            > > > possible? How can it be done.
            > > >
            > > > Regards,
            > > > Chris Vettese[/color]
            > >
            > > Without knowing what is in these tables I can only be general. Set the
            > > rowsource for the first listbox to aquery that returns all the results[/color][/color]
            you[color=blue][color=green]
            > > want from table1. Make the bound column of this list box whichever field[/color][/color]
            is[color=blue][color=green]
            > > the related one from table2.
            > > In the second list box set the rowsource to a query that returns all the
            > > fields you want "...WHERE (table2.FieldNa me = forms!FormName! Listbox1);"
            > > If necessary, use the AfterUpdate event of the first listbox to requery[/color][/color]
            the[color=blue][color=green]
            > > second. this way each choice in the first, will cause the second to[/color][/color]
            change[color=blue][color=green]
            > > its list.[/color][/color]


            Comment

            Working...