Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2003
    Posts
    123

    Unanswered: Selected value in List Box

    This is very rudimentary, but I've completely forgotten how to get a value from the selected row in a list box (no multi-select).

    Say I have three columns: date, item #, description, and 10 rows are displayed in the listbox. When I click on a row, I want to pass the Item # column to a text box.

    I've tried:
    txtSelected.ItemData
    txtSelected.ItemDate(1)
    txtSelected.ItemsSelected
    txtSelected.Column(1)
    but nothing happens, or I get an error. I know I'm probably missing something really easy...

  2. #2
    Join Date
    Nov 2003
    Location
    Warren, PA
    Posts
    52
    In the properties for the list box change the bound column to the column you want to transfer to the textbox
    11/24/2003 | 1234 | Desc. Of Item 1234

    date column is column 1
    item column 2
    Description column 3
    Under the list box control put the column number (1,2 or 3) in the bound column property

    Then the code would just be

    Text box = list box

  3. #3
    Join Date
    Aug 2003
    Posts
    123
    Originally posted by bhummel
    In the properties for the list box change the bound column to the column you want to transfer to the textbox
    11/24/2003 | 1234 | Desc. Of Item 1234

    date column is column 1
    item column 2
    Description column 3
    Under the list box control put the column number (1,2 or 3) in the bound column property

    Then the code would just be

    Text box = list box
    That didn't do it. On the form, the text box is supposed to display the value of the 2nd column of the row that is currently selected. However, the text box is just blank. I need to do this via VBA code, but even if I enter "=[name of list box]" into the text box's control source, I get an error.

  4. #4
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    In the AfterUpdate event of the list box put this code:
    Me![MyTextBox] = Forms![MyFormsName]![MyCtrlListName].Column(1)
    this must work.
    Saludos
    Norberto

  5. #5
    Join Date
    Nov 2003
    Location
    Warren, PA
    Posts
    52
    This code should work but you have to put the reference to the bound column in the form load and not the control otherwise it wont work

    Private Sub Form_Load()
    List7.BoundColumn = 2
    End Sub
    _________________________________________

    Private Sub List7_DblClick(Cancel As Integer)
    Me![Text9] = Me![List7]
    End Sub





    Originally posted by jrn0074
    That didn't do it. On the form, the text box is supposed to display the value of the 2nd column of the row that is currently selected. However, the text box is just blank. I need to do this via VBA code, but even if I enter "=[name of list box]" into the text box's control source, I get an error.

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Try this:

    MyTextBox.Value=MyListBox.Column(1,MyListBox.ListI ndex)

    Remember ... Column ordinals are ZERO based ...

  7. #7
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Lightbulb have you tryed this

    Me.List1.Column(1)

  8. #8
    Join Date
    Aug 2003
    Posts
    123

    Re: have you tryed this

    This is why this seemingly simple task is so frustrating. I know it's not this hard! None of your suggestions work. Either the text box remains empty, or I get run-time error 2448. I've even tried using the Click event of the list box and passing the value to the text box. No luck.

    In reality, what I need to do is open up a form showing the details of the selected record in the list box. The list box is just displaying a few columns of the records. So it needs to pass the indexed column value of the selected row to the 'details' form and to SQL to retrieve all the columns of the record.

  9. #9
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    Why don't post and sample base in Access 97 format to see the problem.
    Saludos
    Norberto

  10. #10
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Question

    You speak of textbox and listbox wich of the two are giving you a problem

    textbox
    or
    Listbox

  11. #11
    Join Date
    Nov 2003
    Location
    UK
    Posts
    12

    Let's see if I understand your problem...

    You have a form ("MainForm") and on this form is a listbox ("Listbox"). This listbox contains a list of items that the user can select from. When an item has been selected you want to open a seperate form ("NewForm") displaying the full details for the selected item. And this is where your problem is - you can't get "NewForm" to display the details for the item selected from "Listbox" in "MainForm"??

    Is this your situation? If so, maybe I can help.
    Are you using Access 97 or 2000?

    regards,
    Last edited by genisys; 11-26-03 at 09:05.

Posting Permissions

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