Consulting

Results 1 to 12 of 12

Thread: Selection From ListBox Not Populating TxtBox

  1. #1
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    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 Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    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 Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    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 Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    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

  8. #8
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    This has been working great, but I just have a quick question about a scenario that has arisen out of utilising this.

    If one of the seleced phrases is identical to another for the first 20 characters (and beyond increasing the 20 value to allow extra matching capabilites) and it stretches over say two paragraphs, is there a way where it might ignore the '& vbCrLf' between the quotation marks to allow matching across to the second paragraph? At the moment if I go back to make edits, the two phrases are selected when only one is required.

    For example:-

    "Unfortunately there are no proportionate lines of enquiry that can be made into this that are likely to lead to any sort of formal outcome." & vbCrLf & vbCrLf & "A referral has been made ....... etc"

    "Unfortunately there are no proportionate lines of enquiry that can be made into this that are likely to lead to any sort of formal outcome." & vbCrLf & vbCrLf & "If the circumstances have changed ....... etc"

    Thanks!

  9. #9
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    Sorry, I forgot to update the thread status.

  10. #10
    I don't have time to investigate this at present, but on the face of it you could use replace to replace the unwanted characters in the string before making the comparison e.g.
    Dim sString1 As String
    Dim sString2 As String
    sString1 = "Unfortunately there are no proportionate lines of enquiry that can be made into this that are likely to lead to any sort of formal outcome." & vbCrLf & vbCrLf & "A referral has been made ....... etc"
    sString2 = "Unfortunately there are no proportionate lines of enquiry that can be made into this that are likely to lead to any sort of formal outcome." & vbCrLf & vbCrLf & "If the circumstances have changed ....... etc"
    sString1 = Replace(sString1, vbCrLf & vbCrLf, " ")
    sString2 = Replace(sString2, vbCrLf & vbCrLf, " ")
    Debug.Print sString1 & vbCr & sString2
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  11. #11
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    I can follow your logic Graham as to how the Replace can remove the & vbCrLf between the two phrases and then placing it back again, but not how this would need to be adapted to work in the template (acknowledged that there are currently no examples in the form that require this, but I am looking to expand on the range of phrases and hence why I am having to seek help).

    The phrases appear in two different areas in the template so I am not sure if the logic you have shown would only need to be applied in one part to achieve the desired result of reading more of the phrase and possibly through & vbCrLf & vbCrLf &.

    I saw that you mentioned that only the first 255 characters (max.) can be read. Will there be an issue if the say first 150 characters were read, but still will not fail to recognise a phrase that was say only 50 characters?

    I hope that my query makes sense?

  12. #12
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    Been having another think about this one and was wondering if the start of each sentence selection could be preceded with say a unique two digit number followed by a forward slash, then once the user had selected either say one, two, three or four selections, it could remove the two numbers and forward slash to leave just the sentence text. I was thinking that this would then make each selection completely unique regardles of if certain selections contained virtually identical text as in the first two shown below. Mind you, there might also be an issue if the user were to change their mind and go back to make different selections.

    For example:

    "01/Unfortunately there are no proportionate lines of enquiry that can be made into this that are likely to lead to any sort of formal outcome." & vbCrLf & vbCrLf & "A referral has been made ....... etc"

    "02/Unfortunately there are no proportionate lines of enquiry that can be made into this that are likely to lead to any sort of formal outcome." & vbCrLf & vbCrLf & "If the circumstances have changed ....... etc"

    "03/There is no CCTV or witnesses that would allow for further investigation to take place." & vbCrLf & vbCrLf & "This does not prevent ....... etc"

    "04/Noted that this has been reported for information ony with no further investigation required."

    Not sure if this is possible to achieve?

Posting Permissions

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