Results 1 to 3 of 3
  1. #1
    winsonlee is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    4

    Writing text to log file.

    I would like to create a log file. But the function that i have always over write the existing one. it doesnt append to the end of the file. what do i need to change to allow me to append the data at the end of the file ?



    Code:
        Private Sub AddLog(ByVal filename As String, ByVal error As String)
        Dim sFileText As String
        Dim iFileNo As Integer
          iFileNo = FreeFile
          Open filename For Output As #iFileNo
          Print #iFileNo, error
          Close #iFileNo
        End Sub

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    dim fs
    dim fAppendFile
    dim sSourceFile as string

    set fs = createobject("Scripting.filesystemobject")
    sSourcefile = "C:\test\outputfile.txt"
    set fAppendfile = fs.opentextfile(ssourcefile, 8)
    '8 indicates you want to append only

    fappendfile.writeline "ERROR"

    fappendfile.close
    set fs = nothing

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Instead of using "OUTPUT", use "APPEND". If the file exists, it will append to current file. If the file doesn't exist, it will be created.

    Code:
        Private Sub AddLog(ByVal filename As String, ByVal error As String)
        Dim sFileText As String
        Dim iFileNo As Integer
          iFileNo = FreeFile
          Open filename For Append As #iFileNo
          Print #iFileNo, error
          Close #iFileNo
        End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. ComboBox writing to text
    By tmcrouse in forum Forms
    Replies: 1
    Last Post: 11-18-2010, 09:10 AM
  2. Replies: 1
    Last Post: 11-05-2010, 04:31 PM
  3. Exporting to Text File
    By blandow in forum Import/Export Data
    Replies: 2
    Last Post: 08-06-2010, 06:02 PM
  4. Text File Link
    By pkell658 in forum Import/Export Data
    Replies: 1
    Last Post: 03-23-2010, 04:46 PM
  5. Data from text file
    By Directlinq in forum Programming
    Replies: 1
    Last Post: 10-19-2009, 02:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums