Results 1 to 5 of 5
  1. #1
    dlewicki is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    11

    Bring up record according to list box selection

    Private Sub List47_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object
    Set rs = Me.Recordset.Clone


    rs.FindFirst "[id] = " & Str(Nz(Me![List47], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub


    I have a list box on a form. And when I click a row in the list box, I want the other fields of the form to populate according to the data in the list box. I have tried the above code and it does not work. What should I check for? Thanks, Dave

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Define "does not work". Error? Incorrect result? What is the data type of ID?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Stressed is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    19
    Quote Originally Posted by dlewicki View Post
    Private Sub List47_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[id] = " & Str(Nz(Me!
    [List47], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub


    I have a list box on a form. And when I click a row in the list box, I want the other fields of the form to populate according to the data in the list box. I have tried the above code and it does not work. What should I check for? Thanks, Dave
    Use the column() function.

    Lets say you have 2 text boxes. txtName and txtPhoneNUMBER and your list box is called lstSelection. Your table is CONTACTS

    I always modify the ROWSOURCE for the list box to use a query (click the ... beside the Rowsource field)

    The ROWSOURCE once you closed (not saved) the query builder, your SQL should like something like (SELECT CONTACS.NAME, CONTACTS.PHONE_NUMBER FROM CONTACTS)

    Select the table then double click to add each table field in your query. The counting starts at 0 meaning that NAME = 0 and PHONE_NUMBER = 1

    In the on Dbl Click event of the list box, use the following code:

    txtName = lstSelection.column(0)
    txtPhoneNUMBER = lstSelection.column(1)

    Repeat this for each field that you wish to populate.

    Every time the user double clicks a record in the listbox it will populate the fields on the form.

  4. #4
    dlewicki is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    11
    Define "does not work". Error? Incorrect result? What is the data type of ID?

    Pbaldy - the existing data in the fields of the form do not change. That's what I mean by does not work... sorry that I wasn't more clear. There is no error message at all.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What is the data type of the ID field? Is that the bound column of the listbox?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Checking List Box Value with Combo box selection
    By empyrean in forum Programming
    Replies: 1
    Last Post: 10-23-2009, 06:01 PM
  2. Replies: 3
    Last Post: 09-26-2009, 01:57 PM
  3. Subform Selection
    By doug adams in forum Forms
    Replies: 2
    Last Post: 06-28-2009, 10:27 PM
  4. Replies: 7
    Last Post: 05-16-2009, 08:08 AM
  5. Replies: 1
    Last Post: 03-09-2006, 12:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums