Retaining formatted hyperlinks in a rich text textbox (AC2013) (1 Viewer)

AOB

Registered User.
Local time
Today, 14:14
Joined
Sep 26, 2012
Messages
615
Hi,

Not sure if what I'm trying to do is simply outside the bounds of what Access 2013 can provide or if I'm just missing something stupid but hoping somebody can help...

I have a user form which acts as a method for users to create saved templates for emails. The form has a textbox (unbound) for the email body piece, set to Rich Text format so they can format the text as they want it and then save the contents to a record in the database so it can be retrieved again later. The corresponding field in the database is also set up as a Long Text with Rich Text format so it can handle the HTML output of the textbox value.

As part of this functionality, I'd like to allow users to insert formatted hyperlinks; that is, not just a raw link, but with a separate display text (in much the same way you could if creating an email in Outlook directly)

Obviously this is a problem as the Rich Text capabilities of a textbox in an Access form don't extend to this (you can type in a hyperlink address but you can't edit the hyperlink to set a separate display text)

To get around this, I wrote a function on the back of a command button to insert a hyperlink. When the user clicks the button, it opens a separate popup dialog where they can enter their link address as well as the text to display instead of the link. I then have some code that constructs the HTML for the formatted hyperlink, á la :

<font color="#5C83B4"><u><a href="http://www.somewebsite.com">Click here for your link</a></u></font>
The function then inserts this HTML into the existing HTML value for the textbox

I appreciate that it's now not possible to click on the link in the textbox itself but that's fine, I don't really care about that, as long as the HTML is saved correctly then once it is transferred into the Outlook message, it should function.

Once the user is happy the email body is as it should be, there is a save button which saves the textbox value (i.e. the HTML) to the database.

Before anyone asks, the problem of the double-quotes is bypassed by replacing them with a placeholder character (e.g. |) when updating the record. And when an existing record is loaded back into the form, that placeholder is replaced back to the double-quotes.

This all works - here's where it gets weird though.... :banghead:

When debugging the code, I track the value in the textbox and the value in the database. Everything looks fine, the values are exactly as I would expect.

I close the form. I reopen it and load up a record. Again, everything looks fine; the HTML in the textbox value is exactly as it should be and the text appears perfectly in the form. Okay, the hyperlinks don't function if you click on them but the most important thing is, the HTML code is correct and they will function in an Outlook message.

I can close and reopen the form as many times as I like, everything works fine. I can navigate around other elements of the form, all is well.

If, however, I click back into the textbox - to make an edit somewhere else in the text - the hyperlink tags in the textbox value disappear?

So now, all of a sudden, they look like this :

<font color="#5C83B4"><u>Click here for your link</u></font>
Note that the "display text" is retained, as is the formatting around it - but the link tags and link address are purged?

It's like Access has decided to review the HTML, without being asked, seen the hyperlink tags and thought "nah, not having that" and just removed them, without prompt

To clarify, they are there when the record is initially loaded and the text in the textbox appears exactly as it should

So obviously if I then save the record again (with my unrelated edits), the hyperlink address is gone

This is obviously a major problem as it means users will have to manually reinsert any hyperlinks any and every time they decide to edit and save a template, which will be incredibly annoying.

Also, because the formatting and display text is retained, it's not immediately obvious what has happened from the interface - I know I'm going to have people asking me where their hyperlinks have gone in the final email output.

Has anybody any suggestions as to how to get around this problem or am I just running blindfold down a dark alley here?

Thanks in advance!

AOB
 

MarkK

bit cruncher
Local time
Today, 06:14
Joined
Mar 17, 2004
Messages
8,180
Is the TextFormat property of the field in the table, and the TextFormat property of the control on the form set to Rich Text? If so, see if it makes a difference to change this back to Plain Text.

When using the Rich Text setting, Access adds tags (and it stands to reason--may remove tags) behind the scenes. Using Plain Text I doubt this will happen.
hth
Mark
 

isladogs

MVP / VIP
Local time
Today, 14:14
Joined
Jan 14, 2017
Messages
18,213
I think it will help us to assist if you provide a stripped down copy of your database with the relevant parts for us to look at.
 

AOB

Registered User.
Local time
Today, 14:14
Joined
Sep 26, 2012
Messages
615
Is the TextFormat property of the field in the table, and the TextFormat property of the control on the form set to Rich Text?
Yes

If so, see if it makes a difference to change this back to Plain Text.
The problem is definitely in the textbox / form rather than the database - there are no issues storing the value in the field, I can read and write the HTML with zero issues, so I don't see much point in changing the properties of the field in the table. And I can't change the properties of the textbox because I'm relying on it to provide me with, in effect, a text editor and also to generate the HTML code for the formatted text.

I think it will help us to assist if you provide a stripped down copy of your database with the relevant parts for us to look at.
I'll try to do that today, will take some time though as the email piece is just one small section of a much larger process. Let me see what I can throw together to help provide some colour.

Thanks guys
 

isladogs

MVP / VIP
Local time
Today, 14:14
Joined
Jan 14, 2017
Messages
18,213
Another thing you could consider is to use a Web browser control instead of your textbox

OR put the hyperlink part in its own separate textbox and use the Edit Hyperlink feature



EDIT
OR use code Application.FollowHyperlink ...
 

Attachments

  • Capture.PNG
    Capture.PNG
    29.1 KB · Views: 1,096
Last edited:

static

Registered User.
Local time
Today, 14:14
Joined
Nov 2, 2015
Messages
823
As far as the control is concerned the url is the display text. The href isn't used.
Becuase the address is invalid it gets removed.

<a href="http://www.somewebsite.com">www.Click_here_for_your_link</a>
 

AOB

Registered User.
Local time
Today, 14:14
Joined
Sep 26, 2012
Messages
615
I think it will help us to assist if you provide a stripped down copy of your database with the relevant parts for us to look at

Here is a severely stripped down version of what I'm seeing (apologies for any clumsiness in the code, this is just a fast and dirty example of the problem rather than anything polished that I'd actually put my name to!)

Three textboxes - on the left, the user input textbox (where a template email body can be constructed). In the middle, the HTML version of that input. On the right, the text as stored in the database table.

Type some text into the first textbox, as if it were the start of an email message. Format sections of text, change font colours, make certain parts bold etc. - then tab off. You'll see the resultant HTML in the second textbox.

Click Save Changes and you'll see the same HTML (sans double-quotes) in the third textbox.

Delete the contents of the first textbox and click Load Record - the saved HTML will be repopulated and displayed as it was.

Now - select some arbitrary text in the textbox (which will become the hyperlink) The Insert Hyperlink button should appear. Click on it and the Insert Hyperlink dialog should appear. Enter the link address and click Insert Hyperlink. The selected text should now be underlined and highlighted text (like a hyperlink).

In the middle textbox, you should see the HTML tags for the hyperlink as expected. Click Save Record and again the HTML is copied to the table, sans double-quotes.

Clear the textbox again. Load Record. The hyperlink still appears as it should and the hyperlink tags are still retained in the textbox value. Click into the textbox and tab out again without making any changes. Still all looks fine.

Now click back into the textbox and make a slight edit (a backspace or add a character) and tab out again. The hyperlink tags have disappeared :confused:
 

Attachments

  • HyperlinkTest.accdb
    516 KB · Views: 416

isladogs

MVP / VIP
Local time
Today, 14:14
Joined
Jan 14, 2017
Messages
18,213
Before I look at your database, have you tried any of the suggestions I made in post #5
 

AOB

Registered User.
Local time
Today, 14:14
Joined
Sep 26, 2012
Messages
615
Another thing you could consider is to use a Web browser control instead of your textbox
From what I can see, a Web Browser control is a static link to a specified address which then displays the target of that address in a control object on the form. That's not what I'm trying to achieve. The contents of this textbox will eventually be transformed into an HTML email message.

The hyperlinks entered by the users are completely arbitrary?

OR put the hyperlink part in its own separate textbox and use the Edit Hyperlink feature
I could keep the hyperlink piece in a separate control but then how to specify where in the email message the embedded link should reside? Also, how would I adapt such a method for multiple hyperlinks? An arbitrary number of them in various positions in the email body?

OR use code Application.FollowHyperlink
Again, this isn't what I'm trying to achieve? That would allow the user to navigate to the address via the interface - they don't want to or need to?

They just want to be able to create a storable email template which can handle embedded hyperlinks which are displayed with a user-friendly display text as opposed to the raw URL.

Does what I'm saying make sense?

I do appreciate the suggestions, I don't really care if I have to go about this in a roundabout way; having this functionality will be extremely beneficial and it's worth the development time!

Thanks for your suggestions!
 

isladogs

MVP / VIP
Local time
Today, 14:14
Joined
Jan 14, 2017
Messages
18,213
A web browser control can contain practically any item that a web page can hold e.g. Formatted text, images and hyperlinks.
From your description, this seems a practical approach to consider.
Please consider this rather than reject it out of hand.

If I can find time later, I'll have a look at your db unless anyone else does so before then.
 

AOB

Registered User.
Local time
Today, 14:14
Joined
Sep 26, 2012
Messages
615
Perhaps I'm looking at the wrong control - when I insert a Web Browser Control from the Design ribbon, I'm immediately prompted to specify the address of the webpage to which the control should link?

It doesn't appear to be something the user could edit themselves as a raw HTML editor?

Am I missing something?
 

Attachments

  • WebBrowserControlWizard.jpg
    WebBrowserControlWizard.jpg
    49.5 KB · Views: 389

isladogs

MVP / VIP
Local time
Today, 14:14
Joined
Jan 14, 2017
Messages
18,213
Perhaps I'm looking at the wrong control - when I insert a Web Browser Control from the Design ribbon, I'm immediately prompted to specify the address of the webpage to which the control should link?

It doesn't appear to be something the user could edit themselves as a raw HTML editor?

Am I missing something?

There is another Active X browser control. One of the very few I use.
It's that one you should look at
 

isladogs

MVP / VIP
Local time
Today, 14:14
Joined
Jan 14, 2017
Messages
18,213
Just had a quick look at this
I got as far as this:
Now - select some arbitrary text in the textbox (which will become the hyperlink) The Insert Hyperlink button should appear. Click on it and the Insert Hyperlink dialog should appear. Enter the link address and click Insert Hyperlink. The selected text should now be underlined and highlighted text (like a hyperlink).

I've done this repeatedly (with & without http://) but nothing happens - the selected text appearance doesn't change & nor does the HTML. I've also tried enclosing the link address in quotes



I've not checked the code but expect you'll be able to see why its not working

All VBA references are present & correct and the project is fully compiled

I've not done anything below as clearly no point whilst that isn't working

In the middle textbox, you should see the HTML tags for the hyperlink as expected. Click Save Record and again the HTML is copied to the table, sans double-quotes.

Clear the textbox again. Load Record. The hyperlink still appears as it should and the hyperlink tags are still retained in the textbox value. Click into the textbox and tab out again without making any changes. Still all looks fine.

Now click back into the textbox and make a slight edit (a backspace or add a character) and tab out again. The hyperlink tags have disappeared
 

Attachments

  • Capture.PNG
    Capture.PNG
    21 KB · Views: 899

isladogs

MVP / VIP
Local time
Today, 14:14
Joined
Jan 14, 2017
Messages
18,213
For info, this is a randomly selected example of a web browser control which includes formatted HTML text, images and a hyperlink. In this case the link to to an external document (PDF) but a web page would work in exactly the same way.



If you think this might be of use I can provide more info on how it was done

NOTE: This is part of an application help feature which was deliberately designed to mimic the style of Windows help
 

Attachments

  • Capture.PNG
    Capture.PNG
    72 KB · Views: 783

nonlinear

New member
Local time
Today, 16:14
Joined
Dec 11, 2023
Messages
8

isladogs you mention about an activeX web browser control but you didn't say WHERE CAN WE FIND IT. So your posts are completely useless.​

 

Gasman

Enthusiastic Amateur
Local time
Today, 14:14
Joined
Sep 21, 2011
Messages
14,262

isladogs you mention about an activeX web browser control but you didn't say WHERE CAN WE FIND IT. So your posts are completely useless.​

Way to go, first post on here and complaining already.
With that attitude, good luck getting support.

Ever heard of Google? :mad:

In fact I'll add you to my IL right now.
 

nonlinear

New member
Local time
Today, 16:14
Joined
Dec 11, 2023
Messages
8
Way to go, first post on here and complaining already.
With that attitude, good luck getting support.

Ever heard of Google? :mad:

In fact I'll add you to my IL right now.
Hahahaha... With your comment you added nothing to my point. If you have something to add about the substance then welcome. I have no time to waste and that is why I made this comment. I sat down and wasted time reading the posts only to find in the end that someone is disrespecting other people's time by mentioning things that do not indicate where and how we will find them. That's called wasting time.
 

isladogs

MVP / VIP
Local time
Today, 14:14
Joined
Jan 14, 2017
Messages
18,213
@nonlinear
You really know how to win friends & influence people. Your first post was bad enough & you've just added to a poor start with your reply to @Gasman

Against my better judgement, I will humour you this once.
Access has a list of built-in ActiveX controls. One of those is called Microsoft Web Browser.
Perhaps you could have spent a couple of minutes checking that for yourself rather than disrespecting the considerable time I spend here & in other forums assisting others
 

nonlinear

New member
Local time
Today, 16:14
Joined
Dec 11, 2023
Messages
8
I have Ms Access 2016 32 bit. I found an ActiveX "Microsoft Web Browser" and a black frame appeared in the form represent a browser.
01.png

Then I wrote some code to use Me.WebBrowser7.ControlSource=...
And it throws an error message
02.png

It looks like that it doesn't work.

But when I use the web browser control which already exists in the default controls then the previous code works!!!
03.png


Both controls trigger the activation of the "Internet Controls" reference in the VBA.
04.png
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 14:14
Joined
Feb 19, 2013
Messages
16,607
And it throws an error message
Message is perfectly clear and with very good reason - the activex web browser does not have a controlsource property. Seems your enquiring mind isn't that good at actual enquiring. You will need to googlebing how to use it
 

Users who are viewing this thread

Top Bottom