Solved

Convert text held in access table to html with bullet points and store in access table

Posted on 2008-10-26
5
363 Views
Last Modified: 2012-05-05
Convert text held in access table to html with bullet points and store in access table. The text has * where the bullet points should start. These need to be replaced with a bullet point and saved to new field in the database.

I need to upload this as a product description to our website and because of google spiders I prefer to have the html created before the upload
Here is an example text

Designed to be hung in the stable. *Add Lik-its to the top section and Little Lik-its to the ball. *Will keep the horse interested as he searches for a tasty reward.

This is the way it should look on the website

Designed to be hung in the stable.
-Add Lik-its to the top section and Little Lik-its to the ball.
-Will keep the horse interested as he searches for a tasty reward.

Could a query handle this?
0
Comment
Question by:oldmillsaddlery
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:calpurnia
ID: 22809414
You'd need to write a function which could then be used in the query.

Try the code below, and include the function in your query like this:

SELECT MyTable.Field1, Convert2HTML([Field1]) AS Expr1
FROM MyTable;






Function Convert2HTML(mystring)
 

Dim newstring As String

Dim nextpos As Integer

Dim nextpos2 As Integer
 

newstring = "<p>"
 

nextpos = InStr(1, mystring, "*")

If nextpos = 0 Then

    newstring = newstring & mystring & "</p>"

Else

    newstring = newstring & Mid(mystring, 1, nextpos - 1) & "<ul>"

    Do While nextpos <> 0

        nextpos2 = InStr(nextpos + 1, mystring, "*")

        If nextpos2 = 0 Then

            newstring = newstring & "<li>" & Mid(mystring, nextpos + 1)

            Exit Do

        Else

            newstring = newstring & "<li>" & Mid(mystring, nextpos + 1, nextpos2 - nextpos - 1)

        End If

        nextpos = nextpos2

    Loop

    newstring = newstring & "</ul></p>"

End If

        

Convert2HTML = newstring
 

End Function

Open in new window

0
 

Author Comment

by:oldmillsaddlery
ID: 22853515
Hi Sorry been away for week thanks for the post . I am a bit lost here. Where you say write function can you explain in more detail?
0
 
LVL 10

Accepted Solution

by:
calpurnia earned 500 total points
ID: 22855103
Copy and paste the code above into a module.

Change the first line to:
   Public Function Convert2HTML(mystring)

Now create a query like this:
  SELECT MyTable.Field1, Convert2HTML([Field1]) AS Expr1 FROM MyTable;
replacing MyTable with the name of your table and Field1 with the name of the field that contains the text you want converted.

Does this give you the desired output?

   
0
 

Author Closing Comment

by:oldmillsaddlery
ID: 31510150
This is the perfect solution and has saved me much time, I am delighted with the solution and the way you handled it. I feel rather guilty that I have not paid you directly for this
0
 
LVL 10

Expert Comment

by:calpurnia
ID: 22858397
I'm glad I could help! By the way, the points you awarded me have resulted in me getting my first EE certification  - Master in the MS Access zone :)
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now