Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB code problem - string

VB code problem - string

Scheduled Pinned Locked Moved Visual Basic
helpc++tutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 41487
    wrote on last edited by
    #1

    Having a problem with the following code: DoCmd.OpenReport "Print - IncompleteMemosbyTeamLeader", acViewPreview,, _ "RequestTo = 'Tod O'Dell'" Only recognises the String as Tod O instead of Tod O'Dell. Can someone please suggest a way to overcome this. I'm not a VB coder. I'm unfamiliar with VB. I assume you could declare Tod O'Dell as a string as would in C++ and use the VariableName. e.g. C++ Example String VariableName = "Tod O'Dell"; Your help would be greatly appreciated:) Nathan Browne

    R J 3 Replies Last reply
    0
    • U User 41487

      Having a problem with the following code: DoCmd.OpenReport "Print - IncompleteMemosbyTeamLeader", acViewPreview,, _ "RequestTo = 'Tod O'Dell'" Only recognises the String as Tod O instead of Tod O'Dell. Can someone please suggest a way to overcome this. I'm not a VB coder. I'm unfamiliar with VB. I assume you could declare Tod O'Dell as a string as would in C++ and use the VariableName. e.g. C++ Example String VariableName = "Tod O'Dell"; Your help would be greatly appreciated:) Nathan Browne

      R Offline
      R Offline
      Ravi_Shankar
      wrote on last edited by
      #2

      Hi, In the criteria, put it in a variable and use Replace function to replace the single quote found with 2 single quotes. Please find an example below to use the same with SQL Server. Dim sSql As String Dim sName As String sName = "O'Leary" sName = Replace(sName, "'", "''") sSql = "Select * from authors where au_lname = '" & sName & "'" Debug.Print sSql Try executing the output of the above SQL statement in Query Analyser under Pubs database... Ravi Shankar S Programmer Analyst iSOFT R&D Pvt Ltd Chennai, INDIA Ph: 91-44-4414980 Extn 1103

      1 Reply Last reply
      0
      • U User 41487

        Having a problem with the following code: DoCmd.OpenReport "Print - IncompleteMemosbyTeamLeader", acViewPreview,, _ "RequestTo = 'Tod O'Dell'" Only recognises the String as Tod O instead of Tod O'Dell. Can someone please suggest a way to overcome this. I'm not a VB coder. I'm unfamiliar with VB. I assume you could declare Tod O'Dell as a string as would in C++ and use the VariableName. e.g. C++ Example String VariableName = "Tod O'Dell"; Your help would be greatly appreciated:) Nathan Browne

        R Offline
        R Offline
        Ravi_Shankar
        wrote on last edited by
        #3

        Hi, You can use the Replace function to replace a single quote with 2 single quotes... Consider the following example: sName = "Tod O'Dell" sName = Replace(sName, "'", "''") DoCmd.OpenReport "Print - IncompleteMemosbyTeamLeader", acViewPreview,, _ "RequestTo = '" & sName & "'" Hope this helps you... Ravi Shankar S Programmer Analyst iSOFT R&D Pvt Ltd Chennai, INDIA Ph: 91-44-4414980 Extn 1103

        1 Reply Last reply
        0
        • U User 41487

          Having a problem with the following code: DoCmd.OpenReport "Print - IncompleteMemosbyTeamLeader", acViewPreview,, _ "RequestTo = 'Tod O'Dell'" Only recognises the String as Tod O instead of Tod O'Dell. Can someone please suggest a way to overcome this. I'm not a VB coder. I'm unfamiliar with VB. I assume you could declare Tod O'Dell as a string as would in C++ and use the VariableName. e.g. C++ Example String VariableName = "Tod O'Dell"; Your help would be greatly appreciated:) Nathan Browne

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          As Ravi_Shankar pointed out (but not so clearly) the problem is that databases use single quotes (or apostrophes; your pick) to delmit the boundries of a string. In order to support the use of single quotes/apostrophes in a string the SQL specification says that a double-single quote/apostrophe '' is used (not "). So rather than the last line being "RequestTo = 'Tod O'Dell'" you need to make it "RequestTo = 'Tod O''Dell'" (note the use of the dobule-apostrophe) Hope that is a bit clearer for you :) James "Java is free - and worth every penny." - Christian Graus

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups