Results 1 to 9 of 9
  1. #1
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46

    Question Paste as plain text in richtext text box

    Is there a way to force text to be pasted as plain text in a rich text text box?


    I would like to harmonise the look of information that my text box are containing and have decided on a font, font size, color to be used. The problem is that my user are coping/pasting information in the text box and not changing the font afterwise.

    I found some links that might have contained the information I wanted, but unfortunately the links are dead.

    I was thinking of using VBA or something but still Learning access.

    Thanks

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    This thread is on very similar lines and may help
    https://www.access-programmers.co.uk...d.php?t=302834
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    Unfortunately the thread you are pointing out to has no happy ending. According to the user there is no way to change the font.
    But i'm pretty sure I did found some piece of VBA code to achieve this but can't find where.

    In the end I mostly want to make sure that when text is pasted in the rich text field if it contains HTML marking such as:
    <font size=5 color="#22B14C"> or <font face="Times New Roman" size=3 color=black> it will get stripped, as I want to apply my own styling. But want to retain the <em> and <strong> for example.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    As someone who contributed the example app in the thread at AWF, I disagree that it has no happy ending.
    I gave two solutions to the OP's problem. Both work without writing code.
    The issue was that the OP wanted to do a mixture of the two solutions and that won't work unless additional code is used.
    Any code would need to strip some or all of the formatting in the original and would be specific to that situation only.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    My understanding of your solutions is to "strip" the rich text by copy/pasting the content in a Notepad and then in the field or to format it properly (perhaps in word) and then copy/paste it in Access.

    The reason why this doesn't bring me my happy ending is that my users are already struggling with the use of a database they won't take the time to format it before hand (or reformat it afterwards) by themselves.

    I don't really know/understand why rich text works this way. In my view specifying a font/size on the textbox should overwrite whatever formating there is.
    So if there's no way to do it otherwise i'm kinda stuck.

  6. #6
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    So I think I found a solution on stackoverflow : https://stackoverflow.com/questions/...ze-not-working

    I created a button that my user can click after entering the content in the comments section. This only affects the font and size leaving the other type of formating in place.

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Glad you found a solution for your needs.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    While I was able to create a button to "reset" the font face and font size I'm encountering an error I didn't see before.

    Here's the code for the module:

    Code:
    Public Function CleanRichText(strTEXT, strFont, nSize)
    
    For i = 1 To 9
        strTEXT = Replace(strTEXT, "size=" & i, "size=" & nSize)
    Next i
    
    strTEXT = Replace(strTEXT, "font face", "font_face")
    strTEXT = Replace(strTEXT, "font" & Chr(13) & Chr(10) & "face", "font_face")
    
    Do While InStr(1, strTEXT, "font_face=" & Chr(34)) > 0
        iCut1 = InStr(1, strTEXT, "font_face=" & Chr(34))
        iCut2 = InStr(iCut1 + 12, strTEXT, Chr(34))
        strLeft = Left(strTEXT, iCut1 - 1) & "font_face=Face"
        strRight = Right(strTEXT, Len(strTEXT) - iCut2)
        strTEXT = strLeft & strRight
    Loop
    
    Do While InStr(1, strTEXT, "font_face=") > 0
        iCut1 = InStr(1, strTEXT, "font_face=")
        iCut2 = InStr(iCut1 + 12, strTEXT, Chr(32))
        strLeft = Left(strTEXT, iCut1 - 1) & "font face=" & strFont & Chr(32)
        strRight = Right(strTEXT, Len(strTEXT) - iCut2)
        strTEXT = strLeft & strRight
    Loop
    CleanRichText = strTEXT
    And the button:

    Code:
    Private Sub CleanTextBox_Click()
        MsgBox ("Updating the comments to Arial 11pts")
        Me.NOTES = CleanRichText(Me.NOTES, Me.NOTES.FontName, 2)
    End Sub

    When I had a sentence with text in a different colour in it it breaks the code.

    For example here's what my unclean text looks like when it has colour in it:

    Code:
    <div><font face="Times New Roman" size=3>So basically any sentence</font><font face="Times New Roman" size=3 color=red>with </font><font face="Times New Roman" size=3>a color in it will break?</font></div>
    And right after clicking the button:

    Code:
    <div><font face=Arial size=2>So basically any sentence </font><font face=Arial size=2 color=red>with </font><font face=Arial color in it will break?</font></div>
    It looks like when the module is run against the colour it doesn't close.

    Any ideas on how to fix this?

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Suggest you post your database as you used a solution from stackoverflow I'm not familiar with
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 2
    Last Post: 09-08-2017, 09:49 AM
  2. Send a plain text message without any prompt
    By lonesoac0 in forum Programming
    Replies: 3
    Last Post: 03-25-2017, 10:07 PM
  3. Copy and paste plain text.
    By 316854 in forum Access
    Replies: 9
    Last Post: 12-14-2015, 09:16 PM
  4. HTML characters in plain text field
    By etorasso in forum Access
    Replies: 3
    Last Post: 09-25-2014, 11:47 AM
  5. Convert rtf to plain text
    By techneophyte in forum Programming
    Replies: 0
    Last Post: 09-08-2010, 11:13 AM

Tags for this Thread

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