Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Apostrophe in data (2000)

    I have the following code:

    Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
    Dim mySql As String
    mySql = "Insert Into tblContents3 Values ('" _
    & ClNam & "', " & Page & ")"

    DoCmd.SetWarnings False
    DoCmd.RunSQL mySql
    DoCmd.SetWarnings True
    End Sub

    It highlights - DoCmd.RunSQL mySql in the above code and

    It gives me a run time error 3075
    Syntax Error (missing operator) in query expression "Alpha Metals's'.
    Whenever it comes to a CLNam that has an apostrophe in it, it gives me this error.
    Short of removing all the aprostrophes in the data, is there a way around this?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Apostrophe in data (2000)

    Does CLNam ever contain a double quote " ? If not, you can change the line setting mySQL to

    <code>mySql = "Insert Into tblContents3 Values (" & Chr(34) _</code>
    <code>& CLNam & Chr(34) & ", " & Page & ")"</code>

    The Chr(34)s insert double quotes around the value of CLNam. If CLNam may contain both single and double quotes, it becomes more complicated.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Apostrophe in data (2000)

    This will work just fine - thanks for your help....

Posting Permissions

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