none
Display MultiLine Text in Textbox Based on Selection in Listbox RRS feed

  • Question

  • In the Word Userform I have a ListBox with rows based in an Access table.  When the user selects a row in the ListBox, additional fields in the Access table are displayed a Textbox or Label.  The problem is I want the Textbox to show each field of additional data on a separate line.  This is similar to form-subform in Access.  The ListBox and the Textbox have a one-to-many relationship so there can be more than one record for each item in the ListBox.  I tried to use vbCrLf in a variable but it does not move the next field to the next line. (see below)

    rs is a query that contain only the records in the Access table that match the ListBox selection (rs![Field1])

    Do Until rs.EOF
        strText = strText & rs![Field2] & vbCrLf & rs![Field3] & vbCrLf & rs![Field4] & vbCrLf
    rs.MoveNext
    Loop

    Monday, February 20, 2012 5:57 PM

Answers

  • The MultiLine property is set to True.  If I set WordWrap to False every field displays as a separate line but the view is truncated.  If I set WordWrap to True each field appears after the next field with no separation.
    • Marked as answer by kaykayme Monday, February 20, 2012 8:41 PM
    Monday, February 20, 2012 8:19 PM

All replies

  • Make sure that you set the MultiLine property of the text box to True, otherwise the vbCrLf will not act as a line feed, but be displayed as ¶.

    Regards, Hans Vogelaar

    Monday, February 20, 2012 8:14 PM
  • The MultiLine property is set to True.  If I set WordWrap to False every field displays as a separate line but the view is truncated.  If I set WordWrap to True each field appears after the next field with no separation.
    • Marked as answer by kaykayme Monday, February 20, 2012 8:41 PM
    Monday, February 20, 2012 8:19 PM
  • MultiLine and WordWrap should both be set to True.

    If you want a blank line between entries, use ... & vbCrLf & vbCrLf & ... instead of just ... & vbCrLF & ...


    Regards, Hans Vogelaar

    Monday, February 20, 2012 8:36 PM
  • Thank you for your answer.  It worked as I needed.  It did not add a blank line after each field but it did put each field on a separate line.
    Monday, February 20, 2012 8:41 PM