Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    85

    Rich Text Box Formatting

    Hi All,



    To date, I have not found a satisfactory solution for this question, so I apologise if it's been asked before.

    I would like to format text in a rich text box. Easy right? Not so fast. I don't want to use the popup menu. It's clumsy and erratic.

    Instead I would like to put my own bold, italic, underline - and all the other good things on buttons above my rich text box - easy right...not so fast.

    You can highlight selected text, but the second you click out from the RTB, you lose the selection. So... My thinking is that you have to record the location of your selection, but that seems not to be easy either.

    Has anybody an example of how I might do this, or can offer any good ideas?

    I'm afraid that using alternative active x controls is not possible, or buying controls where such a facility is included in not an option to me... Hence why I'm looking for a native solution available to standard access.

    Cheers

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    Why do you say the rich text toolbar is clumsy & erratic?

    Also, it is not at all clear to me what you are asking.

    Is it a utility like my Rich Text Editor which is available free?

    Click image for larger version. 

Name:	RTE1.PNG 
Views:	54 
Size:	72.1 KB 
ID:	50597

    Or perhaps you want something more complex like this form which can create both rich text and HTML for use in Access?

    Click image for larger version. 

Name:	RT2HTML.jpg 
Views:	53 
Size:	158.4 KB 
ID:	50598

    The second screenshot also comes from the same article but is part of a commercial app for schools
    I created it many years ago but remember it being very complex to create at the time
    The toolbar buttons are for use when creating HTML
    For the rich text, I'm using the built in rich text toolbar
    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

  3. #3
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    85
    Thank you Colin.

    These seems like great resources. I am familiar with Rich text, but don't know much about HTML editing.

    I'm not building a commercial application. I'm building a too that allows me to write documents utilising Access to aid in text storing and manipulation.

    In any case, your HTML version seems to contain the features that I want - that is, format buttons and selections that can be applied to the text field.

    I like the right click popup menu in the rich text box, but I'd rather prefer to be able to use buttons. except with RTB, the focus is shifted from the RTB and the selection is lost.

    I've tried recording the location of the cursor, but it's exceptionally difficult, so that's why i'm interested in a solution that adequately permits text formatting without losing focus.

    Cheers

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    Rich text is a cut down version of HTML. There are some common features.
    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
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    85
    Yep, I get that.

    But my question is how can I approach the study of making an editor such that I have a rich text field (or html, or whatever feild) and house buttons atop said field, such that I can click them without losing focus, and edit the text content (make bold, colored, styled, etc).

    Now I'm not looking for someone to provide a full scale application - I'm just a poor basic access dev - but an example would be very helpful.

    Cheers

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    except with RTB, the focus is shifted from the RTB and the selection is lost.
    you can get that information and store it in a global variable or tempvar in one of the control's events (perhaps the lost focus event)

    look for the properties selStart, selLength and selText.

    your button to make bold might be something like

    myRTC=replace(myRTC,glbSelText,"<Strong>" & glbSelText & "</Strong>")

    Then no need to return to the control - user just click back when required.

    You will find it is not quite as simple as that - you will need to control scrolling for example and if the selText is repeated, then all instances will be affected, so you need to think about how that might work as well

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    I'm slightly confused by your comments about the rich text toolbar.
    Did you try the free rich text editor from my article?
    Using the form, select a word in one of the records e.g. by double clicking. The toolbar appears but the selected word retains focus. Alter its appearance using the toolbar. Rinse and repeat.

    Sorry but I can't supply the other more complex form as its part of a commercial app.
    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
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    85
    Thanks again for responses.

    Any rich text tool bar sits outside the rich textbox control. If you click a button, the focus goes to that button and away from the RTB control. Meaning that anything you selected becomes unselected.

    I reviewed the free rich text editor - and yes, I agree you can right click and raise the popup with your right click functionality. You can also, click the access toolbar, which seem to permit font changes without losing focus. But I absolutely do not want to display the access toolbar (or VBE at all).

    CJ_London suggested that you store the variable information - which I have tried. e.g. the cursor location, then the cursor length. Unfortunately this creates many more problems - counting for the html tags, determine their opening and closing, determine if the selection was inside the appropriate tag, determine where you selected text backwards or forwards.... and so on and so forth.

    In any case, the problem with using RTB seems far more of a waste of time that previously thought. Perhaps you made it work - and I respect your desire to retain your IP - but that doesn't answer my previous question. How do I do it?

    I don't want your IP. what I want is to learn how and understand how to do these things, which seems a far more satisfying.

    I appreciate your responses, and I continue to form alternative ideas as a consequence, so thank you again.

    Cheers

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    As previously explained the form used in my commercial app has a rich text textbox control on the left and HTML on the right displayed in a web browser control

    For the rich text control, I use the built in rich text toolbar. It works fine and I never saw any reason to find an alternative. In any case, I've never tried to disable that toolbar and it may not be possible to do so

    The 30 buttons in a row on the form toolbar are used to format the contents of the HTML in the web browser control.
    For example, clicking the Bold button whilst a text selection is highlighted runs this code

    Code:
    Me.WBrowser.Object.Document.execCommand "Bold", False, Null
    The Hyperlink button does this:
    Code:
    Me.WBrowser.Object.Document.execCommand "CreateLink", True
    Other buttons are used to cut/copy/paste, undo/redo, add numbered or bulleted lists, italic/underline/strikethrough text, superscript/subscript, change text or background colour/ highlight text, left/centre/right align or justify, indent/outdent; add line, image, table, rectangle etc, etc...

    In other words, they provide almost all the features found in HTML web pages though I'm using this feature to create rich text and HTML help pages displayed in an Access form.

    This is a randomly selected example of HTML generated using this approach - there are over 400 such help pages with images, links etc

    Click image for larger version. 

Name:	Capture.PNG 
Views:	34 
Size:	88.4 KB 
ID:	50609

    Each of those pages can also be printed:

    Click image for larger version. 

Name:	Capture2.PNG 
Views:	32 
Size:	216.6 KB 
ID:	50610

    You may be able to display your rich text in a web browser control and do something similar but I never tried as the built in toolbar works fine for me

    Anyway, hope that's sufficient to get you started
    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

  10. #10
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    85
    Thank you for your examples.

    Your tool looks fantastic and I'm sure your work is worthy of high praise! I'm sure most devs can only dream of putting something like it together.

    Update: I will say that I using an ActiveX Microsoft web browser linked to a text box, I was able to edit the text, and even apply the bold, italics, underline formatting. However, it seems not to permit Enter key press. This seems a bit odd. Is there a method to allow for enter keypress when typing text and inserting new lines? Even better is there a means to edit the Standard Web browser control?

    Little steps of frustration...



    Cheers
    Last edited by journeyman; 08-07-2023 at 10:39 PM.

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    I did warn you from the start that creating this form was a lot of work.

    The answer to the new line question is shown at the top of the larger screenshot in post #2.
    As far as I remember I am using a standard web browser control (not ActiveX) but I'd have to check as its almost 15 years since I made it and I haven't used it in a long time.
    The new Edge browser control wouldn't work for this as .Object code isn't allowed
    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

  12. #12
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    85
    The answer to the new line question is shown at the top of the larger screenshot in post #2.
    From your general description and graphics, I think you must have done some amazing work.

    I want to be able to emulate that, but, I don't want to buy it. I want to make it for myself. Now I'm not trying to rip you off. I'm sure your work is worth every penny.

    * The ActiveX Webbrower control allows instant and immediate text change - I can type into it - but you can't type CTRL-Enter and express a new line. It doesn't work!
    * The ActiveX Webbrower control does no such thing. I can't type the letters 'ABC' let alone CTRL-Enter. It simply won't type a word. Perhaps I'm not connecting it right. in any case, it doesn't work the way you are describing it.

    However, based on one of your responses, I can apply "Bold" via a external button, and that works. It's awesome, except that I can't type anything into a standard control, and I can't CTRL Enter into an Active X control.

    Surely somebody has an example of how its done - that I shouldn't have to pay $400 for.

    Cheers

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    Your two bullet points both reference the ActiveX browser but contradict each other. Should one of those points be for the standard browser control?

    It definitely works for me though I haven't used it for many years and would need to check whether I'm using the standard web browser or an ActiveX component.

    Whilst I wish you luck creating this, I will again warn you that it will be a lot of work. It took me many hours over several weeks.
    I did this in order to generate full HTML so I could also include images, videos and hyperlinks for the help articles.
    Each article has two versions. A basic rich text item and an HTML version with additional, info, images etc.
    For the rich text versions, I just use the built in popup toolbar.

    I'm still not convinced that doing all of this for formatting rich text is worth the huge effort involved.

    There may be other examples online but I don't recall finding anything similar at the time I created this.
    You may be able to find the code required for each button by searching the MS site.. However, I deduced most, if not all of them, myself.

    You made it clear that you don't want to purchase my version and that is absolutely fine. In fact, far better to do it yourself.
    In any case, its embedded as a small component of a huge app for schools and is not currently available for sale as a separate component.

    Perhaps it should be...but I suspect it would take quite a lot of time to make it work as a standalone item.

    Good luck
    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

  14. #14
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    I've just had another look at the form.
    I am using an ActiveX web browser control in which I type directly
    When I create a new record, this information appears by default:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	27 
Size:	66.0 KB 
ID:	50617

    Clicking Create Default HTML then gives me the basic header and body text sections:
    Click image for larger version. 

Name:	Capture2.PNG 
Views:	26 
Size:	16.9 KB 
ID:	50618

    Anything entered (in either the rich text or HTML windows) is saved to a table in plain text format with all HTML codes
    Clicking the View Source Code button makes a hidden textbox visible showing the saved code

    Click image for larger version. 

Name:	Capture3.PNG 
Views:	26 
Size:	20.2 KB 
ID:	50619

    Here's an example with more text added including a bulleted list and an embedded image

    Click image for larger version. 

Name:	Capture4.PNG 
Views:	26 
Size:	61.5 KB 
ID:	50621

    Anyway, whilst I can't share that form, I do have another rich text editor that I have shared in the past. Its attached below
    However it does still use the rich text toolbar. See if that helps you
    Attached Files Attached Files
    Last edited by isladogs; 08-09-2023 at 07:19 AM.
    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

  15. #15
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    85
    Thanks for your help.

    I found an example from Stephen Lebans, then studied and reverse engineered it to understand what made it tick.

    I'll be honest, there is no possible way I understand a lot of it, but I took the functional code then stripped out any irrelevant coding that just complicated matters. and made it work.

    I learned out that the Webrowser control event KeyPreview had to be set to Yes, (this was perhaps the single point of failure that was never clear anywhere) .

    Then I rebuilt my own from scratch.

    I now have a functional webbrowser control that I can edit. Granted, the HTML code is not pretty, but baby step right.

    Anyway, you've provided some insight into the complexity of doing it, so thank you again.

    Cheers

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 06-18-2021, 04:22 PM
  2. Rich text field not displaying rich text properly
    By CodeLiftSleep in forum Access
    Replies: 4
    Last Post: 01-24-2018, 10:59 AM
  3. Replies: 3
    Last Post: 06-04-2017, 01:02 PM
  4. Replies: 4
    Last Post: 08-07-2015, 07:49 AM
  5. Replies: 1
    Last Post: 03-13-2012, 08:35 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