Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lookups (97, 2000)

    I have a listbox displaying all the values from a column in a table. I want a separate textbox to display the relevant value from the second column whenever a value from the listbox is selected. Is this easy to do? Do i use some kind of lookup function?

    <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Thanks,

    pmatz

  2. #2
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Lookups (97, 2000)

    Oops, i realised this is easy now. Just did the list box wizard with 'lookup a value from table' option and works fine.
    Thanks,

    pmatz

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Lookups (97, 2000)

    The easiest solution is to include the second column in the list box. To do this:
    <UL><LI>Include the second column in the Row Source of the list box.
    <LI>Set the Column Count property to 2.
    <LI>If you would like to display both columns in the list box itself, set the Column Widths property to (for example) 1";1".
    <LI>If you would like to hide the second column in the list box, set Column Widths to (for example) 1";0".
    <LI>Set the Control Source of the text box to

    =
    • (1)

      where ListBoxName is ... you guessed it.
    Note: counting columns of a list box starts at 0, so Column(1) is actually the second column.

  4. #4
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Lookups (97, 2000)

    Thanks Hans, I am going to try that way now!

    I noticed that when i used the wizard, Acess makes the following code

    Sub LstDep_AfterUpdate()
    ' Find the record that matches the control.
    Me.RecordsetClone.FindFirst "[DepCode] = '" & Me![lstDep] & "'"
    Me.Bookmark = Me.RecordsetClone.Bookmark
    End Sub

    and links it to the listbox. This works too, but i dont understand it so well. I understand your method with the column counts.

    Thanks.
    Thanks,

    pmatz

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Lookups (97, 2000)

    The code does something else: it makes the form move to the first record whose DepCode matches the value selected in the list box.

    The method I suggested doesn't make the form move to another record, it only displays the second column in a text box.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •