-
Aug 14th, 2008, 08:53 AM
#1
Thread Starter
Member
VBA: Convert & to & [Access 97]
Hi all,
Yep, using software which is 11 years old! Anyway, I just wanted something which is similiar to htmlentities() in PHP, should there be one. If no-one knows of one could you point me in the direction of functions to use to make one? i'm guessing just a series of string replacers would do it.
Thanks,
Andy
-
Aug 14th, 2008, 09:32 AM
#2
Re: VBA: Convert & to & [Access 97]
Hope this helps:
Code:
Dim sText1 as String
Dim sText2 as String
sText1 = "dog & cat & good moring"
sText2 = Replace(sText1, "&", "&")
'-- To prevent the case "&" already existed in sText1:
sText2 = Replace(sText1, "&", "!@#$%")
sText2 = Replace(sText2, "&", "&")
sText2 = Replace(sText2, "!@#$%", "&")
Edit: The last 3 lines can be combined in one line as:
Code:
'-- To prevent the case "&" already existed in sText1:
sText2 = Replace(Replace(sText1, "&", "&"), "&", "&")
Last edited by anhn; Aug 14th, 2008 at 06:15 PM.
-
Aug 14th, 2008, 10:04 AM
#3
Thread Starter
Member
Re: VBA: Convert & to & [Access 97]
That is really helpful Anhn, but I wanted something to replace any necessary html entities.
If it is just going to be a function I need to make with loads of replaces then so be it, I was hoping there might be some kind of existing function with VBA which would do it all for me :P
Thanks for your help though!
Also (I didn't want to make a second post) any ideas whats wrong with this?...
Set rst = db.OpenRecordset("Import table - TEST")
For r = 1 To RecordCount
For Each fld In rst.Fields
msgbox rst![County]
Next
Next r
Last edited by udjamaflip; Aug 14th, 2008 at 10:11 AM.
-
Aug 14th, 2008, 06:25 PM
#4
Re: VBA: Convert & to & [Access 97]
Originally Posted by udjamaflip
That is really helpful Anhn, but I wanted something to replace any necessary html entities.
If it is just going to be a function I need to make with loads of replaces then so be it, I was hoping there might be some kind of existing function with VBA which would do it all for me :P
Thanks for your help though!
Code:
Function ConvertToHTMLCode(sText As String, sChar As String, sCode As String) As String
ConvertToHTMLCode = Replace(Replace(sText, sCode, sChar), sChar, sCode)
'-- The inner replace is used in case sCode already existed in sText
' If you are sure no sCode existed in sText, just simply use one replace:
' ConvertToHTMLCode = Replace(sText, sChar, sCode)
End Function
Your new question should be in a new thread posted in Database Development forum.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|