Results 1 to 5 of 5

Thread: Resolved--String manipulation in VBA

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    17

    Resolved Resolved--String manipulation in VBA

    Hi ppl,

    I have following situation. I have a form containing First name text box and the last name text box. When I press confirm button on this form, it concatenated First name and the last name to give me full name as a parameter that I am passing to the next form. However, problem comes if a user has last name like "O'Neil" or "O'Hair" or "O'Dell" the compiler does not understandd that apostrohy sign and gives me a runtime error.

    Does anyone know how do I access such string which contains characters such as " " " , " ' ", "`"

    Thanks in advance,
    Vikram Bartakke
    Last edited by vikram.bartakke; Mar 7th, 2005 at 03:40 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: String manipulation in VBA

    Usually we see this issue when dealing with a query to a db. To get around that we would just
    double up on the single quote using the replace function.

    VB Code:
    1. strString = txtFirst & "," & txtLast
    2. strString = Replace(strString, "'", "''")'
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: String manipulation in VBA

    Quote Originally Posted by vikram.bartakke
    Hi ppl,

    I have following situation. I have a form containing First name text box and the last name text box. When I press confirm button on this form, it concatenated First name and the last name to give me full name as a parameter that I am passing to the next form. However, problem comes if a user has last name like "O'Neil" or "O'Hair" or "O'Dell" the compiler does not understandd that apostrohy sign and gives me a runtime error.

    Does anyone know how do I access such string which contains characters such as " " " , " ' ", "`"

    Thanks in advance,
    Vikram Bartakke
    To place (") in a String in VB, use (""). ie..

    VB Code:
    1. strText = "This ""String"" Contains double-quotes"
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    17

    Re: String manipulation in VBA

    Hi ppl,

    Thank you very much for your help. It worked fine. I knew about this problem but the time when i actually implemented this application i was ignorant

    Ignorance is not bliss always )

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: String manipulation in VBA

    We were glad to have helped

    Ps, dont forget to Resolve your thread
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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