+ Reply to Thread
Results 1 to 8 of 8

Display a UserForm based on Data selected in another UserForm's ListBox

  1. #1
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Display a UserForm based on Data selected in another UserForm's ListBox

    Hi all,

    I have a macro that returns a list of records from an Access database and displays each of these records in a listbox on one of my UserForms.

    I'm wondering - is there any way for me to display a separate UserForm with text boxes that are populated with data according to which specific record is selected in the listbox from the first UserForm?

    Example: The ListBox displays a list of students returned from an Access database, showing StudentID, LastName, FirstName, Address for columns in the listbox. If I click on the record that shows data for John Doe, (ID# 123, Address 123 Cranberry Lane) I want to display a separate UserForm that has 4 text boxes (one for each attribute) and populate them according to John Doe's data. (ID, Last Name, First Name, and Address fields would be populated appropriately).

    Thanks again all for the help!

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Display a UserForm based on Data selected in another UserForm's ListBox

    Rough code (assuming Userform2 is the other form):
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Display a UserForm based on Data selected in another UserForm's ListBox

    Thanks very much for the input! It looks like it's about to do it's magic, but right when it gets to this block of code I get the following error:

    "Could not get the List property. Invalid property array index."



    Thanks again for the help!

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Display a UserForm based on Data selected in another UserForm's ListBox

    On which line?

  5. #5
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Display a UserForm based on Data selected in another UserForm's ListBox

    On the first line of the "With" block:

    frm.textbox1.text = .list(.listindex, 0)

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Display a UserForm based on Data selected in another UserForm's ListBox

    And you have selected an item?

  7. #7
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Display a UserForm based on Data selected in another UserForm's ListBox

    Yes. And now, randomly without changing anything at all, I'm getting an error that says "Object Required" and it's highlighting the 2nd line of your code block "Set frm = New UserForm2" ...very strange...

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Display a UserForm based on Data selected in another UserForm's ListBox

    I'd need to see the workbook.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1