Results 1 to 2 of 2
  1. #1
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    St Louis, Missouri, USA
    Thanked 1 Time in 1 Post

    Replace String in Text (Access 2000/SP2)

    I need to replace some characters in the first row of a text file. I'm having a brain freeze and cannot remember the syntax.
    <pre>Sub ReplaceFreakCharacters(HubFile As String)
    Dim nFile As Long
    Dim sFile As String
    Dim NewHead As String
    nFile = FreeFile
    <font color=red> 'Open the AbandonServiceHub export and change the + strings to periods
    ' on row one ONLY</font color=red>
    Open HubFile For Input As nFile
    Line Input #nFile, sFile
    NewHead = Replace(sFile, "+", ".", 1, -1)
    Print #nFile, NewHead <font color=red>Blows up here</font color=red>
    <font color=blue> Debug.Print sFile
    Debug.Print NewHead</font color=blue>
    Close nFile
    End Sub</pre>

    The original text looks like <pre>"Input+ActionUDFInput+TeeLocationFtg","Input+ ActionUDFInput+TeeLocationDirLdmk" </pre>

    and the result like <pre> "Input.ActionUDFInput.TeeLocationFtg","Input.Actio nUDFInput.TeeLocationDirLdmk"</pre>

    Access did not like periods in the Exxpressions so I used plus signs. The rest of the file is OK. Can I make the change directly in the text file or do I need to export to a second??

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Replace String in Text (Access 2000/SP2)

    Since you open the file for input, you cannot write to it. You should open the file for input and another one for output. Read each line from the first file, modify as needed, then write to the second file.
    When done, close both, delete the first file and rename the second one.

Posting Permissions

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