+ Reply to Thread
Results 1 to 9 of 9

Userform - filling textboxes from a ListBox Selection

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Userform - filling textboxes from a ListBox Selection

    A userform I am trying to finish populates a listbox of returns from a search query. I want then when an item double Clicked to fill a userforms text boxes

    All textboxes are called "Ddtxt_1" up to "Ddtxt_46"

    The textbox numbers are in the same order as the listbox index

    I want to display the results so they can be edited - Ddtxt_20 does not exist but the listbox index entry for column 20 will exist

    This will not work and stalls with ListIndex & i highlighted

    Any Ideas how to change>>>
    Please Login or Register  to view this content.
    Last edited by nigelog; 02-02-2017 at 08:38 AM.

  2. #2
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Userform - filling textboxes from a ListBox Selection

    Try these modifications

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Userform - filling textboxes from a ListBox Selection

    Try these modifications

    Please Login or Register  to view this content.
    Last edited by Maudibe; 02-01-2017 at 09:19 AM. Reason: duplicate post

  4. #4
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Userform - filling textboxes from a ListBox Selection

    Hi Maudibe, this is stalling on line indicated but it does display the first correct entry Ddtxt_1 from Listbox 0 ...(ListBox1.List(i)="AC")....

    you have a variable lr but it is not referenced ... any ideas?? "Cells(lr, i + 1)………….Application Defined or Object Defined error"

    Please Login or Register  to view this content.
    Last edited by nigelog; 02-01-2017 at 11:00 AM.

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Userform - filling textboxes from a ListBox Selection

    Dont think this the way to go as I have noticed it is only returning the first ListIndex entry from the top row in the listbox, not the selected row in the listbox


    Public Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    For i = 0 To 45
    If i <> 19 Then
    Controls("Ddtxt_" & i + 1).Value = ListBox1.List(i)
    Cells(lr, i + 1) = ListBox1.List(i) 'XXXXXXXXXXXXXXXXXX
    End If
    Next
    End Sub

    Ive attached a workbook, Userform in question is Driver Detail, searching from Textbox1
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Userform - filling textboxes from a ListBox Selection

    Cells(lr, i) = Controls("Ddtxt_" & i).Value = ListBox1(.ListIndex & i)
    nicelog,

    I was following your lead in your code. You had variable "lr" in your code and not defined so I thought maybe this was a global variable set to some value. You were also looping the i value in your ".ListIndex & i" so I took a guess that you were attempting to loop through the values and place in each textbox....guess not.

    it is only returning the first ListIndex entry from the top row in the listbox, not the selected row in the listbox
    ListBox1.value will return the selected value
    Listbox1.ListIndex will return the index of the selected row -1
    Listbox1.ListIndex +1 will return the selected row
    ListBox1.List(2) will return the value with the index of 2 which is the third value.

    which value(s) are you attempting to populate in each of the textboxes?

    Maud

  7. #7
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Userform - filling textboxes from a ListBox Selection

    Hi Maud

    The value in the text boxes should be the text box order is equal to the column order of the selected value EXCEPT for Ddtxt_20 (doesnt exist) which ignores column 19

    This was original working code that I wanted to change

    Please Login or Register  to view this content.
    Any pointers appreciated.. variable lr was declared in a an earlier reply post which wrote the same boxes back to the worksheet - I didn't notice it was there, apologies
    Last edited by nigelog; 02-02-2017 at 06:34 AM.

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

    Re: Userform - filling textboxes from a ListBox Selection

    This does what you want except it errors for column AH, so if you fix that it's working.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  9. #9
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Userform - filling textboxes from a ListBox Selection

    Sorted AH and works, thankyou Bakerman2

    14 of Ddtxt_ display a date and the format has appeared as "mm dd yyyy" - just checked the list index values and same so need to look at that if cant be changed at this point..
    Last edited by nigelog; 02-02-2017 at 08:38 AM.

+ 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. Userform ListBox depending on a previous Listbox selection
    By Figolu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-23-2015, 02:08 PM
  2. Userform populate listbox with search from multiple textboxes
    By chendysworld in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2012, 11:12 AM
  3. [SOLVED] Populate listbox columns with entries from textboxes on userform
    By AndyE in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2012, 11:05 PM
  4. Populating UserForm TextBoxes from ListBox results
    By AGrace in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2010, 03:07 PM
  5. filling userform listbox
    By simonhall in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2006, 08:43 PM
  6. filling userform textboxes
    By Pierre via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2005, 04:05 PM
  7. selection all textboxes in userform at once
    By Marthijn Beusekom via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2005, 10:06 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