Results 1 to 12 of 12
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479

    Retreve Text box (Formatted)

    The text in my text box may be a long line of text which Access wordwraps.
    How can I find the wordwrap positions?
    I want to replicate the text in another app... but of course it becomes the initial long line of text again .



    Thanks for any help/info.

  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    433
    Access automatically handles the wordwrap.
    the simplest one i can think is to create Exact dimension
    of the Original textbox that wrap to the other app.

    or if you are VBA savvy, you can compute the TextWidth and TextHeight
    of the Text and compare it to the TextWidth and TextHeight of
    the Textbox.

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    Hi Jo, the destination (for data backup) is an Excel Comment. I found it also can do wordwrap
    so playing around with that. It seems do-able but ChatGPT has given me a line of Excel code that errors!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I have found, and other posts have experienced, that Chatgpt does not produce error free vba. Often getting/returning/suggesting functions or constructs that do not exist in Access. These are"hallucinations" (made up constructs).
    Last edited by orange; 03-06-2025 at 08:22 AM. Reason: spelling

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    If you need to control it you'll have to do it manually (insert your own wrap points) or with code. If code, you'll have to use a fixed width font because an "i" is not as wide as a "W" and you can't have that.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Quote Originally Posted by orange View Post
    I have found, and other posts have experienced, that Chatgpt does not produce error free vba. Often getting/returning/suggesting functions or constructs that do not exist in Access. These are"hallucinations" (made up constructs).
    I would venture a guess that chatgpt doesn't know the difference and trains on whatever it finds including bad code.

    Following what Micron said, I have this code which limits the length of long strings
    Code:
    Function LoopString(strIN As String, strLen As Integer) As String
       
        Dim  K As Variant, strOut As String
        Dim strA As String, strB As String, strLeftOver As String
        
        Dim col As New Collection
        
        Do While InStr(strIN, "  ") > 0
            strIN = Replace(strIN, "  ", " ")
        Loop
    
    
        Do While InStr(strIN, vbCrLf) > 0
            strIN = Replace(strIN, vbCrLf, " ")
        Loop
        
        strLeftOver = strIN
        
        Do Until Len(strLeftOver) = 0
    
    
            strA = Mid(strLeftOver, 1, strLen)
    
    
            If Len(strLeftOver) < strLen Then
            
                col.Add strLeftOver
                strLeftOver = Right(strLeftOver, Len(strLeftOver) - Len(strLeftOver))
    
    
            Else
    
    
                strB = Mid(strA, 1, InStrRev(strA, " "))
                col.Add strB
    
    
                strLeftOver = Right(strLeftOver, Len(strLeftOver) - Len(strB))
    
    
            End If
    
             Loop
    
        For Each K In col
             'Debug.Print K
            strOut = strOut & K & vbNewLine
        Next
     
        LoopString = strOut
        
    End Function
    Code:
    ?LoopString("Hope you are doing well. I have a pdf/word form which has description text to be entered into three lines therefore I want to split the description string into multiple lines of characters say 40 chrs.",40)
    
    Hope you are doing well. I have a 
    pdf/word form which has description 
    text to be entered into three lines 
    therefore I want to split the 
    description string into multiple lines 
    of characters say 40 chrs.
    Code:
    ?LoopString("Hope you are doing well. I have a pdf/word form which has description text to be entered into three lines therefore I want to split the description string into multiple lines of characters say 40 chrs.",75)
    
    Hope you are doing well. I have a pdf/word form which has description text 
    to be entered into three lines therefore I want to split the description 
    string into multiple lines of characters say 40 chrs.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    That coulg be very, very useful. Thanks @moke123 will give it a go.

  8. #8
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    It worked VERY nicely. Solved a big problem.
    If no space chars in strIN would if instr(strIN," ") = 0 or if instr(Left(strIN,strlen), " ")= 0 be the best trap?Or maybe doesn't matter.

  9. #9
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Quote Originally Posted by Middlemarch View Post
    It worked VERY nicely. Solved a big problem.
    If no space chars in strIN would if instr(strIN," ") = 0 or if instr(Left(strIN,strlen), " ")= 0 be the best trap?Or maybe doesn't matter.
    If no spaces it would be a problem. (Unless the string is less than the desired line length)
    It's purpose is really a single paragraph sentence.

    What the code does is replace any double spaces with a single space and replaces any vbcrlf with single spaces.
    Then it loops through the string getting as close to the desired line length without splitting a word in half. It uses the space to separate whole words.
    As the length of each line is determined it adds that piece to a collection along with a vbCrLf and removes it from the string and the loop continues.
    Lastly it loops through the collection concatenating the new string as the functions result.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  10. #10
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    Do you have a preference for how a No Space condition is handled?
    Its ideal for what I'm doing. No spaces should never happen, but it if does it's an endless loop.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Do you want to simply report that this input string does not have a space or carriage return?
    OR
    Do you want to check the length of such an input string (no space or carriage return) and
    IF
    The length is less/equal your desired length, simply output the string.
    Else
    If the length is greater than your desired length, then cut the string at your desired length, and output the string fragment.
    Repeat with remainder of input string until the entire string has been processed.

    Update for consideration:

    Here is a small revision to Moke's LoopString code to allow for a long text string with or without a space character.

    Code:
    ' ----------------------------------------------------------------
    ' Procedure Name: LoopString
    ' Purpose: To shorten a long string into parts of <= strLen.
    '          Maintain punctuation and no splitting of words
    ' Revision: Allow a long text string with/without space character(s)
    '
    'Moke's comment from https://www.accessforums.net/showthread.php?t=90689&p=531637#post531637
    '
    'What the code does is replace any double spaces with a single space and replaces any vbcrlf with single spaces.
    'Then it loops through the string getting as close to the desired line length without splitting a word in half.
    'It uses the space to separate whole words.
    'As the length of each line is determined it adds that piece to a collection along with a vbCrLf and
    'removes it from the string and the loop continues.
    'Lastly it loops through the collection concatenating the new string as the functions result.
    '
    ' Procedure Kind: Function
    ' Procedure Access: Public
    ' Parameter strIN (String): Long input string
    ' Parameter strLen (Integer): Max length to output lines
    ' Return Type: String
    ' Author: Moke
    ' Revision: Jack
    ' Date: 07-Mar-25
    ' From Moke  https://www.accessforums.net/showthread.php?t=90689&p=531630#post531630
    ' ----------------------------------------------------------------
    Function LoopString(strIN As String, strLen As Integer) As String
       
        Dim K As Variant, strOut As String
        Dim strA As String, strB As String, strLeftOver As String
        Dim col As New Collection
        ' replace double spaces to single space
        Do While InStr(strIN, "  ") > 0
            strIN = Replace(strIN, "  ", " ")
        Loop
        ' replace carriage returns to single space
        Do While InStr(strIN, vbCrLf) > 0
            strIN = Replace(strIN, vbCrLf, " ")
        Loop
        'revised string to adjust/parse
        strLeftOver = strIN
        
        ' Parse the revised string and add the line segments to the collection col
        Do Until Len(strLeftOver) = 0
            strA = Mid(strLeftOver, 1, strLen)
            
     ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     ' 7/Mar/25 Revison to allow long text with/without a space character
     '          If space char exists, split at the space char
     ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            If InStr(strA, " ") = 0 Then
                'process nonspace string
                'add string fragment to col
                col.Add strA
                strLeftOver = Mid(strLeftOver, strLen + 1)
            Else
            
                If Len(strLeftOver) < strLen Then
                    col.Add strLeftOver
                    strLeftOver = Right(strLeftOver, Len(strLeftOver) - Len(strLeftOver))
                Else
                    strB = Mid(strA, 1, InStrRev(strA, " "))
                    col.Add strB
                    strLeftOver = Right(strLeftOver, Len(strLeftOver) - Len(strB))
                End If
            End If
        Loop
        
        ' Process the lines in the collection col
    
        For Each K In col
            'Debug.Print K
            strOut = strOut & K & vbNewLine
        Next
     
        LoopString = strOut
        Debug.Print strOut 'for testing
    End Function

    Sample test/result:

    With a space char
    Code:
    ?loopstring("abcdefghijklmnopqr stuvwxyz",11)
    abcdefghijk
    lmnopqr 
    stuvwxyz
    Code:
    ?loopstring("abcdef ghijklmnopqrstuvwxyz",11)
    abcdef 
    ghijklmnopq
    rstuvwxyz

    Without a space char

    Code:
    ?loopstring("abcdefghijklmnopqrstuvwxyz",9)
    abcdefghi
    jklmnopqr
    stuvwxyz
    With multiple spaces(as per original)
    Code:
    ?loopstring("If the length   is greater than    your desired length, then cut the string.",20)
    If the length is 
    greater than your 
    desired length, 
    then cut the 
    string.
    Last edited by orange; 03-11-2025 at 07:50 AM. Reason: more info

  12. #12
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Thanks Orange. I didn't have a chance to get back to this.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 6
    Last Post: 11-22-2022, 01:17 PM
  2. Currency formatted Text Box Question
    By data808 in forum Access
    Replies: 4
    Last Post: 05-09-2014, 12:50 PM
  3. Creating formatted body text in Ms Outlook
    By capitala in forum Forms
    Replies: 2
    Last Post: 04-24-2013, 10:20 PM
  4. Trouble with date/time formatted as text...
    By fatboymedic in forum Import/Export Data
    Replies: 2
    Last Post: 09-25-2012, 10:34 AM
  5. Pasting formatted text into memo field
    By joekuhn in forum Access
    Replies: 0
    Last Post: 07-08-2011, 02:01 PM

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