VB code problem - string
-
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
-
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
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
-
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
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
-
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
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