Results 1 to 4 of 4

Thread: VBA: Convert & to & [Access 97]

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    33

    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

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    33

    Re: VBA: Convert & to &amp; [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.

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: VBA: Convert & to &amp; [Access 97]

    Quote 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.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width