using replace in string value

  • right this worked fine at home but does not at work!!!!


    stdtext is the date format "05/02/2006" after this runs on my pc which is running office 2000 it converts it to "05_02_2006"


    now at work we are running 97 which probably is the reason why it does not work! Please can anyone help me?

  • Re: using replace in string value


    Boromuse,


    When you say it does not work, what error do you get? Or does it execute but not replace the characters you expect?


    Also, check to see if Replace is a function in 97, not sure if it was there or not. Also you do not need the final 1 in the replace statement since this is the default value for the optional parameter.


    A.
    PS I suspect someone will point youin the direction of code tags- you might want to do it before being told off! :)
    A.


    A.

  • Re: using replace in string value


    i think its something to do with the libary reference!
    its coming up with

    Code
    compile error :
    sub or function not defined
  • Re: using replace in string value


    spot on thank you for that just trying to put it in a loop cause that single line is only running through once lol :rock:

  • Re: using replace in string value


    Could you not use Format?

    Code
    Dim stdText As String
    stdText = "05/02/2006"
    If IsDate(stdText) Then
        stdText = Format(stdText, "ddmmyyyy")
    End If
    
    
    MsgBox stdText

    Boo!:yikes:

  • Re: using replace in string value


    Quote from norie

    Could you not use Format?

    Code
    Dim stdText As String
    stdText = "05/02/2006"
    If IsDate(stdText) Then
        stdText = Format(stdText, "ddmmyyyy")
    End If
    
    
    MsgBox stdText


    I had not actually thought of that :)
    thank you for the idea

  • Re: using replace in string value


    Using norie's suggestion of the Format you can also add the _'s if required.
    [vba] stdText = Format(stdText, "dd_mm_yyyy") [/vba]
    I'm a little confused by the use of replace then. Why are you checking for things such as |,? and *

    [h4]Cheers
    Andy
    [/h4]

  • Re: using replace in string value


    well it was if the user had put a different figure in but with the format it has just fixed and got rid of that so thank you!

  • Re: using replace in string value


    also the reason why im using format of "06/02/2006" is because im running a query where it saves the data that has the same date but then when saving the file i'm saving it as "06_02_2006" as the date format is not valid! :)

  • Re: using replace in string value


    ok this is annoying get another problem!!!


    everything is running spot on but when i run there query after everything being set to the "dd/mm/yyyy" it opens the new query and the date is being set in the way of the US "mm/dd/yyyy" so WTF how do i stop this????

  • Re: using replace in string value


    right what i have got is a form with a txtbox that has date format as "06/02/2006" so thats "dd/mm/yyyy"


    then it creates the query

    Code
    DoCmd.OpenQuery ("qryStaffListQuery")


    this opens up and has the criteria as "mm/dd/yyyy" which is a complete pain!
    cause i would have to reorder my date but saying that i have just thought i could just format the result to a hiden txtbox or string with the format of "mm/dd/yyyy" !!!!

  • Re: using replace in string value


    Thats it people its now working after reformating the date to the us style :)
    thank you everyone for the help :) :) :) :) :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!