+ Reply to Thread
Results 1 to 11 of 11

Populating a userform listbox from a database

  1. #1
    Registered User
    Join Date
    01-31-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    19

    Populating a userform listbox from a database

    All,

    I am developing a spreadsheet (using macro code found in this forum) to allow users to search for people who speak a specific language. The spreadsheet is attached.

    I have created a userform on the "Database" sheet that has a listbox at the bottom that populates with records when I search for someone using the 'Name' box.

    The problem that I am having is that when I enter "Person" and get the 30-odd records appear in the listbox, I click on say Person 5 BUT the userform fields do not update themselves fully with the correct information.

    I found the following thread

    http://www.excelforum.com/excel-prog...d-replace.html

    that has a recommended solution, yet because my userform is a combination of textboxes and comboboxes and not simply textboxes, it doesn't seem to work. The macro name is ListBox1_Click()

    Does anyone have a solution to my problem?

    I have other problems, but will post these as separate threads.

    Thanks

    James
    Attached Files Attached Files
    Last edited by James_B; 02-12-2010 at 02:21 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Populating a userform listbox from a database

    When you are setting range references you are not fully qualifiying them

    You need to include the sheet object in both places when refering to the range.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    01-31-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Populating a userform listbox from a database

    Thanks for the quick response Andy.

    Are you saying that I should amend all my FindAll() and "Find_Click() macros where i set ranges? i.e.

    Find_Click() macro:

    Please Login or Register  to view this content.
    I will change the code and let you know what happens.

    Thanks again

    James

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Populating a userform listbox from a database

    As a start yes.

  5. #5
    Registered User
    Join Date
    01-31-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Populating a userform listbox from a database



    Doesn't seem to work when I choose a record in the listbox. Just changes everything up until the second langauge entry as it did before.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Populating a userform listbox from a database

    Your filtering is not correct in the FindAll routine

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-31-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Populating a userform listbox from a database

    Macro code changed, but no difference in the listbox clicking action.

    It still doesn't update all the fields with the correct data from the database.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Populating a userform listbox from a database

    I have added another listbox to the form. This is used to store the row number for each item found.
    You can then use this row number to populate the form when a person is selected in the list.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-31-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Populating a userform listbox from a database

    Thanks for the amendments. You amended a redundant form, but I will transfer the amended code across and give that a try.

    Is this new listbox something that I can hide from the user?

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Populating a userform listbox from a database

    yes, just set the visible property to False.

  11. #11
    Registered User
    Join Date
    01-31-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Populating a userform listbox from a database

    Cheers,

    Transferred it over and it seems to be working. I will check it some more and then change the thread to Solved.

    Thanks Andy, much appreciated

+ 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