Results 1 to 12 of 12
  1. #1
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167

    How can i update text file on C:

    Dear friends,


    I need your help in the following problem.
    I have a text file (Slash.txt) which is stored in on C:\ ProgramData\Dash\Slash.txt. I'm using this file in order to store some numbers (usually max 15digits). I can do this using vba code (example attached).

    What is the problem:
    If the file exist on path C:\ ProgramData\Dash\Slash.txt i cannot update the data...because something going wrong.. If the file does not exist, everything its ok. Vba creates new folder into path as well as new text file into this.

    So, i need help on how can i update the existing txt file with new data, but i need also a way using a command button to delete this text file if i wanted..

    Your help is very important because i'm stacked several days ago...



    Thanks
    Text File Streaming.mdb

  2. #2
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    95
    I am doing this regularly in a couple of steps.

    Function FolderExists(strPath As String) As Boolean

    On Error Resume Next

    FolderExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)

    End Function

    Once that function is established, follow with:


    Function CreateFolder()
    'On Error Resume Next
    Dim strDirectoryPath As String


    If FolderExists("Full Path to folder")) = True Then
    DoCmd.OutputTo acOutputReport, "Report Name", acFormatPDF, "full file path and file name, including all backslashes and file extension", False
    Exit Function
    Else
    MkDir "Full directory name")

    DoCmd.OutputTo acOutputReport, "Document Name", acFormatPDF(change for other format), "full file path and file name, including all backslashes and file extension", False
    End If

    End Function

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    you can do a lot more with your filesystemobject commands

    For instance

    fso.fileexists (check to see if the file exists first)
    fso.createtextfile (create the text file instead of opening an existing one)

    do while fsoFile.atendofstream
    'get to the end of the file
    loop

    fsofile.writeline "blah blah" - to append a line to the end of the file.

  4. #4
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Thanks Guys,

    Can anybody give me one attached example because i'm not so expert to understand on how can modify the code?

    Regards,

    George

  5. #5
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    95
    Don't know about rpeare's fso examples, but just modify and paste mine into a module. You obviously have to enter your own file names and file paths, but in the event that triggers this just put CreateFolder(). That should do it for you.

  6. #6
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Good morning all,

    Can anybody give me an example on how can delete data which are stored into text file using vba solution?

    Regards,

  7. #7
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    95
    Are you speaking of deleting data within the file or deleting the file itself?

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Quote Originally Posted by bcmarshall View Post
    Are you speaking of deleting data within the file or deleting the file itself?
    Ηι,

    I mean to delete data within the file and not the file... Actually i want to update the data (usually its only one line with number) with new data..and refresh..
    Please note that: the file is on path C:\ProgramData\Data\Slash.txt. What i need to do is
    1. When the splash form open, i wand to check if the Folder: Data exist on C:\ProgramData and if not, must create the folder.
    2. Then, if the folder exist i need using a command button (cmdUpdate) to do the following:
    a) To check if the number on text file (Slash.txt) is matching with the field [pID] on Spash form, and if so to give me a msg "The number exist".
    b) If the number does not match with the field [pID] i want to update it with the new one..

    i wish somebody to help because i'm not so familar and expert in vba..

    Thanks in advanced

  10. #10
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    95
    I'm sorry, but I don't have any idea how to accomplish this. However, it appears that the suggestion made my rpeare does have that capacity. Hopefully he can offer the solution to you.

  11. #11
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    This is a very straight forward set of code, I already gave you the methods to use (createfile, fileexists), in addition if you want to check if the folder exists you use folderexists and createfolder

    Folder exists:
    https://msdn.microsoft.com/en-us/lib...=vs.84%29.aspx

    Create folder:
    https://msdn.microsoft.com/en-us/lib...=vs.84%29.aspx

    File exists:
    https://msdn.microsoft.com/en-us/lib...=vs.84%29.aspx

    Create text file:
    https://msdn.microsoft.com/en-us/lib...=vs.60%29.aspx

    really all you have to do is google 'filesystemobject <x>' where x represents what you want to do

    if memory serves your code is already opening the file and reading it you're only adding a few pieces to handle exceptions.

  12. #12
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    95
    Thank you rpeare. I was unfamiliar with this. Because of you I've learned something valuable.

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

Similar Threads

  1. Replies: 4
    Last Post: 09-09-2015, 12:10 PM
  2. Replies: 6
    Last Post: 11-08-2013, 11:18 AM
  3. Replies: 2
    Last Post: 12-27-2012, 09:37 AM
  4. Replies: 3
    Last Post: 07-30-2012, 02:16 PM
  5. How to update table if linked ot text file
    By cory_jackson in forum Import/Export Data
    Replies: 7
    Last Post: 01-03-2012, 03:19 PM

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