+ Reply to Thread
Results 1 to 19 of 19

User Form ListBox - Find Records (ListBox Populating Issue)

  1. #1
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    User Form ListBox - Find Records (ListBox Populating Issue)

    Hello:

    I'm trying to troubleshoot my code that finds all records that matches data entered into Member# (textbox), and populates a ListBox if more than 1 record is found. Everything works perfectly, the only thing I can't figure out is why, when multiple records are found, the ListBox is not being populated on the correct lines. I've set the properties on the ListBox to indicate column Headers. However, when the data is pasted into the ListBox, it is being pasted onto the 2nd line (after the header) - so it looks something like this:

    Header line (nothing is populated)
    line 1 - nothing is populated
    line 2 - displays header from the datatab
    line 3 - displays the first instance of the record found
    line 4 - displays the second instance of the record found

    I've been racking my brain for days....I'm hoping someone will be able to help me resolve this. THANK YOU IN ADVANCE FOR YOUR ASSISTANCE!


    Here is my code:

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    06-12-2015
    Location
    Maryland, USA
    MS-Off Ver
    2010
    Posts
    83

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    If i understand your problem correctly you need to initiate the n variable at -1, not at zero.

    When you have multiple records, you a matrix is empty on position (I,0)

    try this:


    Please Login or Register  to view this content.
    or i might be misunderstanding your problem.
    Got help? Pls give rep.
    If you do R&D learn VBA

  3. #3
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Thank You, JoeFoot! You definitely understood my issue. I made the change to set n = -1, but it looks the data is still off one row. I would expect the header to be in the defined header row (set properties on ListBox to indicate Headers). Below is what the data now looks like:

    Header Row (nothing is populated)
    line 1 - displays header from the datatab
    line 2 - displays the first instance of the record found
    line 3 - displays the second instance of the record found

    I tried to change n=-1 to n=-2, but I get a "Run-time error '9" Subscript out of range"

    I do appreciate your time!!!! thank you!

  4. #4
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Quote Originally Posted by LONeillSSC View Post
    Thank You, JoeFoot! You definitely understood my issue. I made the change to set n = -1, but it looks the data is still off one row. I would expect the header to be in the defined header row (set properties on ListBox to indicate Headers). Below is what the data now looks like:

    Header Row (nothing is populated)
    line 1 - displays header from the datatab
    line 2 - displays the first instance of the record found
    line 3 - displays the second instance of the record found

    I tried to change n=-1 to n=-2, but I get a "Run-time error '9" Subscript out of range"

    I do appreciate your time!!!! thank you!
    Just some additional information - I did try changing the properties on the ListBox for ColumnHeades to "False" - and the data then posts into the ListBox correctly. I'd prefer to have the ColumnHeads if possible, but it seems that this is what is preventing the data from pasting properly - where the headers from the datatab past into Row1, instead of ColumnHead of the ListBox.

  5. #5
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    OK....I'm getting there....
    I figured out how to get the headers from the data tab to actually past into the ColumnHeads on the ListBox - I needed to add the following code:

    Please Login or Register  to view this content.
    But now I'm getting Run-time error '70: Permission Denied, and it's pointing to this line of the code:
    If n > 0 Then Me.ListBox1.Column = a

    I'm so close.........I'm sure it's something that's an easy fix that I just can't figure out because of my limited knowledge of VBA....once again....THANK YOU for any help you can provide!!!!

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    You can't have headers unless you are populating the listbox from a range via RowSource.

    If you really want headers you could add a set of labels above the listbox, populate them with the headers and align them with the appropriate columns.

    Also, if you do use RowSource you can't use other methods, eg AddItem, Column etc to populate the listbox, that's why you get the 'Permission denied' error.
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Thanks, Norie....So it sounds like i need to modify my original code posted above?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    I thought you said the code worked when you set to False?

    If that's the case why not do that and try my suggestion of a set of labels for the headers.

  9. #9
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Hi Norie:

    The ListBox will have 31 columns of data - from what I read, if you do headers the way you suggest, as you scroll through the columns, the headers won't scroll as well. I will continue to play with this. Thank you!

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Why would you want the headers to scroll?

    Shouldn't they be a permanent fixture at the top/above the listbox?

    If you were populating the listbox from a range using RowSource and had ColumnHeads set to True the headers wouldn't scroll either.

  11. #11
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    OK....I've got my ListBox for the found records working - not how I ideally would like it, but it serves it's purpose of identifying multiple records so the user can select the record to be edited. Now I'm stuck with my Save code. I've tried to recall a record, edit it, and save the changes, but nothing is happening when I hit save - which means it's encountering an error, but I' can't tell where. Here is my code:

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    FORM mod 070115 Sample.xlsm

    Here is a sample of my database if this will help.

  13. #13
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Still trying to figure this out....

    Quote Originally Posted by LONeillSSC View Post
    OK....I've got my ListBox for the found records working - not how I ideally would like it, but it serves it's purpose of identifying multiple records so the user can select the record to be edited. Now I'm stuck with my Save code. I've tried to recall a record, edit it, and save the changes, but nothing is happening when I hit save - which means it's encountering an error, but I' can't tell where. Here is my code:

    Please Login or Register  to view this content.

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Your code stops on following line

    Please Login or Register  to view this content.
    for the simple reason that you don't assign a value to r at the beginning of your code.

    I guess r represents the rownumber of the record you're trying to save changes to, but you have to lookup the rownumber first in your database before you can go further saving your changes.
    In order to achieve this every record will need a unique identifier that you can use to retrieve the correct rownumber to save your changes.

  15. #15
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Thanks, Bakerman2! I've modified the code to the following, where I set the value of r, but I still get the same issue, nothing is happening:

    Please Login or Register  to view this content.

  16. #16
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    I've made a small example file because you're still missing the point.
    View the code, specially the CommandButton1 code(Save Changes).
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Ah....I think I understand what you are saying. I will play around with this over the weekend and let you know how I make out. THANK YOU SO MUCH!!! Have a great one!

  18. #18
    Registered User
    Join Date
    08-19-2014
    Location
    USA
    MS-Off Ver
    2007
    Posts
    13

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    bakerman2 - THANK YOU SO VERY MUCH!!!! Your solution worked PERFECTLY, with a few minor tweaks!!!! (sorry for the delay - I didn't get to attempting your solution until this morning!) Once again, THANK YOU!!!!

  19. #19
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: User Form ListBox - Find Records (ListBox Populating Issue)

    Glad I could help you out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Need help with populating Listbox from another Listbox(selection); across userforms.
    By SoulPrisoner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-28-2013, 12:54 PM
  2. Having problems populating a multicolumn listbox changing Listbox column with a loop.
    By Aristizabal95 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2013, 12:41 PM
  3. Populating a listbox based on column of first listbox
    By tucanj in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-13-2013, 09:26 PM
  4. Listbox of Unique Records populating another listbox
    By web2xs in forum Excel General
    Replies: 1
    Last Post: 04-16-2009, 11:27 PM
  5. populating a listbox on a user form?
    By lrhodes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2006, 07:05 PM

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