Consulting

Results 1 to 7 of 7

Thread: Selection From ListBox Not Populating TxtBox

  1. #1
    VBAX Tutor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    295
    Location

    Selection From ListBox Not Populating TxtBox

    I seem to be going around in ever decreasing circles.

    I'm trying to get any selction from a ListBox to populate a defined TxtBox. At the moment the ListBox populates from the array okay, but selecting anything leaves the TxtBox empty.

    The ListBox is called lbReason and the TextBox txtReason.

    Thanks!
    Steve
    Attached Files Attached Files

  2. #2
    see if this will work for you.
    i don't know much of word vba so you need
    to find a way to insert all those nfa reasons.
    https://www.dropbox.com/s/m51natrjx3...20OEL.zip?dl=0

    sorry unable to attached. it says Connection unsecure.

  3. #3
    VBAX Tutor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    295
    Location
    Okay, I've managed to sort myself out all but one small point. How to keep the selections from the ListBox "selected".

    At the moment I can fill out my form okay. But when I go back to edit my document the selections made previously are now not highlighted in the ListBox.
    Attached Files Attached Files

  4. #4
    You would have to read the contents of the text box and compare the paragraphs with the options they refer to and then check the list items that relate to those options.
    See attached.
    Attached Files Attached Files
    Last edited by gmayor; 08-01-2021 at 12:17 AM.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Tutor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    295
    Location
    Many thanks, Graham!

    I'd orignally checked the post prior to you putting up the solution. Having thought about how to even start, I knew that I wouldn't come up with a solution myself.

    I was trying to approach it in the order that you had suggested, but looking at what I had scribbled down on a piece of paper was nowhere near.

    I'd come back to the post to add another query to ask if the approach would be different if there was also some text in the TextBox that had been manually input i.e. not one or more selections from the ListBox?

    One other question. What does the number 20 refer to here?

    If InStr(1, sCC, Left(ArrReason(lngReason), 20)) > 0 Then

  6. #6
    If there is manually entered text in the text box that you want to relate to the list box, then while you may get the text box to read the content of the control, there is nothing to relate it to the list box so it will disappear when you update the form. It would be better not to allow manual entry here and add another text box for ad hoc comments if required. If you make that text box optional,and nothing is entered into it, you can fill the content control it relates to with a zero length space i.e. ChrW(8203) and thus is will disappear from the document, but still be available for updated comments.

    The 20 is a reflection that many of your texts are longe than 255 characters which is the string limit. If you try and search for the full strings, the process will not see those that are over 255 characters. Thus the code only looks at the first 20 characters which provide unique values for each string.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  7. #7
    VBAX Tutor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    295
    Location
    Thanks once again, Graham.

    I was trying to think ahead in case there were instances that might not be covered by the ListBox selections. I'll keep this information in mind should the need arise.

    The explanation of the 20 makes perfect sense.

    Thanks again!
    Steve

Posting Permissions

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