Using Replace help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Clant1
    New Member
    • Feb 2008
    • 13

    #1

    Using Replace help please

    Im using the following code
    [code=vb]
    queerey = Replace(Text3, "or", "' or OrderID ='")
    strSQL2 = "SELECT * FROM tblorder where orderID = '" & queerey & "'"
    DoCmd.OpenRepor t "tblorder1" , acViewPreview, strSQL2
    MsgBox strSQL2
    [/code]
    The idea is that the i can enter 1 or 2 for example and they will show in a report which i have got set up but when i output the string it comes out as
    SELECT * FROM tblorder where orderID = '1 ' or orderID = ' 2'
    which means that it wont work because of the spaces. I have tried it using
    [code=vb]
    strSQL2 = "SELECT * FROM tblorder where orderID = '1' OR orderID = '2'"
    [/code]
    and that worked and the only thing different is the spaces.
  • VBWheaties
    New Member
    • Feb 2008
    • 145

    #2
    Originally posted by Clant1
    Im using the following code
    [code=vb]
    queerey = Replace(Text3, "or", "' or OrderID ='")
    strSQL2 = "SELECT * FROM tblorder where orderID = '" & queerey & "'"
    DoCmd.OpenRepor t "tblorder1" , acViewPreview, strSQL2
    MsgBox strSQL2
    [/code]
    The idea is that the i can enter 1 or 2 for example and they will show in a report which i have got set up but when i output the string it comes out as
    SELECT * FROM tblorder where orderID = '1 ' or orderID = ' 2'
    which means that it wont work because of the spaces. I have tried it using
    [code=vb]
    strSQL2 = "SELECT * FROM tblorder where orderID = '1' OR orderID = '2'"
    [/code]
    and that worked and the only thing different is the spaces.
    I'm not sure what you are asking or what your issue is.
    If you have a space, you can easily replace it.

    Code:
    'Use Space function to return 1 length space: 
    Var = Replace(Text, Space(1), "")
    
    'heres another way:
    Var = Replace(Text, " ", "")

    Comment

    • Clant1
      New Member
      • Feb 2008
      • 13

      #3
      Cheers mate i didnt think of doing that thanks alot.
      [code=vb]
      queerey = Replace(Text3, "or", "' or OrderID ='")
      queerey = Replace(queerey , Space(1), "")
      queerey = Replace(queerey , "or", " Or")
      queerey = Replace(queerey , "or der", "order")
      [/code]
      Thats how it is now if any 1 wants to see the fix. Thanks alot

      Comment

      Working...