stripping quote characters?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Leferve

    stripping quote characters?

    Hey folks -

    In vba, how do I get rid of quote characters in strings? Or at least escape
    them automatically for making SQL INSERT statements? I looked in the help
    index, but nothing jumped out at me.

    Steve


  • Terry Kreft

    #2
    Re: stripping quote characters?

    Look at the Replace function.


    --
    Terry Kreft
    MVP Microsoft Access


    "Steve Leferve" <lefevre.10@osu .edu> wrote in message
    news:c6r9fs$7a0 $1@charm.magnus .acs.ohio-state.edu...[color=blue]
    > Hey folks -
    >
    > In vba, how do I get rid of quote characters in strings? Or at least[/color]
    escape[color=blue]
    > them automatically for making SQL INSERT statements? I looked in the help
    > index, but nothing jumped out at me.
    >
    > Steve
    >
    >[/color]


    Comment

    • Steve Leferve

      #3
      Re: stripping quote characters?


      "Terry Kreft" <terry.kreft@mp s.co.uk> wrote in message
      news:sfOdnapVHs BnsAzdSa8jmA@ka roo.co.uk...[color=blue]
      > Look at the Replace function.[/color]


      Thanks, Terry. That's just what I needed.

      Now I'm having problems replacing the Quote character with an empty string.
      Shouldn't the below work? My strings still have extra quote characters.

      If IsNull(rst!Comm ent10) Then
      strSQL = strSQL & ""","""
      Else
      strSQL = strSQL & """" & Replace(rst!Com ment10, Chr(34), "") & """,
      "
      End If


      Comment

      • Terry Kreft

        #4
        Re: stripping quote characters?

        Yes, it should do, theonly thing I've found is that Replace (in early
        versions at least) required the supposedly optional Compare argument.

        So try

        If IsNull(rst!Comm ent10) Then
        strSQL = strSQL & ""","""
        Else
        strSQL = strSQL & """" & Replace(rst!Com ment10, Chr(34), "",
        compare:=vbBina ryCompare) & ""","
        End If

        Or if you want to get rid of the If statement you could just use

        strSQL = strSQL & """" & _
        & Replace(rst!Com ment10 & "", Chr(34), "",
        compare:=vbBina ryCompare) & ""","


        --
        Terry Kreft
        MVP Microsoft Access


        "Steve Leferve" <lefevre.10@osu .edu> wrote in message
        news:c6rck1$7g4 $1@charm.magnus .acs.ohio-state.edu...[color=blue]
        >
        > "Terry Kreft" <terry.kreft@mp s.co.uk> wrote in message
        > news:sfOdnapVHs BnsAzdSa8jmA@ka roo.co.uk...[color=green]
        > > Look at the Replace function.[/color]
        >
        >
        > Thanks, Terry. That's just what I needed.
        >
        > Now I'm having problems replacing the Quote character with an empty[/color]
        string.[color=blue]
        > Shouldn't the below work? My strings still have extra quote characters.
        >
        > If IsNull(rst!Comm ent10) Then
        > strSQL = strSQL & ""","""
        > Else
        > strSQL = strSQL & """" & Replace(rst!Com ment10, Chr(34), "") &[/color]
        """,[color=blue]
        > "
        > End If
        >
        >[/color]


        Comment

        Working...