Results 1 to 5 of 5
  1. #1
    BruceUK is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2011
    Posts
    48

    Question about inserting text with linefeed characters into a text box via VBA procedure

    Hi everyone,



    I have a form with a large text box. The text box is visible but can not be keyed in, so it has the following settings:

    Visible = Yes, Enabled = No, Locked = Yes

    The text box is also several lines deep. I have some VBA code within a form module that places some structured text into this text box using a For-Next loop.

    The code is essentially like this:

    Dim strVBAIncrementalText(4) As String
    Dim strVBARequiredText As String
    Dim lngVBACount As Long

    strVBARequiredText = ""
    For lngVBACount = 1 To 4
    strVBARequiredText = strVBARequiredText & strVBAIncrementalText(lngVBACount) & Chr(10)
    Next lngVBACount

    Me.txtRequiredText = strVBARequiredText

    So by using the Chr(10) (linefeed character), I am trying to make it go to a new line for each piece of incremental text. However, the new line is not being actioned. The four pieces of text are just being placed end-to-end along the same line (subject to the usual wrapping within the text box).

    Incidentally, in the text box, I've tried setting the 'Enter Key Behavior' attribute to 'New Line In Field', but this has no effect. In any case, I assume this would apply only if text were actually being typed into the text box, which is obviously not the case here.

    Can anyone suggest how I can make each piece of incremental text start on a new line in the text box?

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you need a linefeed and carriage return - try

    strVBARequiredText = strVBARequiredText & strVBAIncrementalText(lngVBACount) & vbCRLF

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    IIRC, You need to have both line feed and carriage returned. I think its Chr(10) and Chr(13). Anyway, I use VbCrlf.
    strVBAIncrementalText(lngVBACount) & VbCrlf

  4. #4
    BruceUK is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2011
    Posts
    48
    Many thanks, Ajax and ItsMe, that worked fine. I'll try to remember that one!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use vbCrLf

    or

    Chr(13) & Chr(10) - yes, in that order, the reverse will result in more space between lines
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Inserting text box between two labels
    By BatmanMR287 in forum Reports
    Replies: 4
    Last Post: 07-06-2015, 01:45 PM
  2. Text box with more than 255 characters
    By ssissons in forum Forms
    Replies: 6
    Last Post: 07-25-2014, 08:32 AM
  3. Inserting Data into fixed text
    By Earthmover in forum Access
    Replies: 6
    Last Post: 02-09-2012, 11:12 PM
  4. Inserting text from a function
    By Mclaren in forum Programming
    Replies: 3
    Last Post: 03-08-2011, 01:29 PM
  5. characters in text boxes
    By Matthieu in forum Access
    Replies: 0
    Last Post: 04-08-2010, 11:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums