Removing HTML within Access Database

Syringer

Lifer
Aug 2, 2001
19,333
2
71
So we import information and it's filled with HTML tags, and I want to find a way to easily replace it with the Expression Builder.

The PlainText function doesn't work very well as the <br> <p> tags etc. create new lines within the new field, and leaves some of them blank.

The best way would probably be to create a replace function like:

Replace(field, "<*>","")

Where all fields that start with < and end with > are removed. How would I do this though?
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
This is the most obvious solution, but you have to put a replace function for every possible html opening and closing tag, which is not very fun.

UPDATE table SET Field1 = Replace(Replace(Field1, '<p>', ''), '<br>', '')

So your other better choice is to use a User Defined Function.
This guy wrote some VBA code to strip out the HTML tags from a string:
http://www.helium.com/items/251916-how-to-create-a-vb-function-to-remove-html-code-from-a-string

Use this guys function in your Access Solution and call it from SQL like:

UPDATE table SET Field1 = PrepareForMetaTag(Field1)
 

Syringer

Lifer
Aug 2, 2001
19,333
2
71
Can you use a wildcard within Access queries? That's what I was going for with the <*>. I'm new to Access so I've never used a User Defined Function so I'll give that a try..