+ Reply to Thread
Results 1 to 18 of 18

Stop appending record in text file

  1. #1
    Forum Contributor
    Join Date
    12-03-2014
    Location
    India
    MS-Off Ver
    2016 .......
    Posts
    390

    Stop appending record in text file

    Ai I am using following code to create folder & text files on the basis of information in column "A"

    but after creating file once if I run again same macro it is appending record by duplication of record.
    I want to pass message that "File already exists" & don't want to append record

    Please Login or Register  to view this content.
    Thanks in advance

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Stop appending record in text file

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    12-03-2014
    Location
    India
    MS-Off Ver
    2016 .......
    Posts
    390

    Re: Stop appending record in text file

    It NOT works properly because macro creates only single record file for different nomenclature.
    I want all records of respective numbers in single file viz.
    008Outward26122018 ---- 1 record
    013Outward26122018 ---- 3 records
    009Outward26122018 ---- 2 records
    While running code for every line of record it passing the message 'file already exists' & I have approx min. 3000 records in a single file so it is very much time consuming.
    I need if there is file available the records must not be added twice i.e. duplicate record.
    A single message i.e. file already exist for a single FILE.
    as well as debug option coming for File Created Successfully msgbox.

  4. #4
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Stop appending record in text file

    Hi Sanju,

    but after creating file once if I run again same macro it is appending record by duplication of record.
    I want to pass message that "File already exists" & don't want to append record
    I think you mean you dont want to append duplicate record in created file is'nt it?

    I want all records of respective numbers in single file viz.
    if yes then there is not existing created file issue, you need to check the record which you have to append is duplicate or not.
    Regards,
    MohanS


    "Perfection is not attainable, but if we chase perfection we can catch excellence." - Vince Lombardi

    You can simply say thanks by clicking "*Add Reputation" icon

  5. #5
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Stop appending record in text file

    Hi Sanju,

    See what i read your question

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Stop appending record in text file

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  7. #7
    Forum Contributor
    Join Date
    12-03-2014
    Location
    India
    MS-Off Ver
    2016 .......
    Posts
    390

    Re: Stop appending record in text file

    Hi
    I am hereby attaching sample file.
    In column A there is text records & by using following code by which it creates files by using fName = Mid(Cells(r, "A"), 35, 3) of the same columns .
    The code create 1 folder of date specified in C2.
    The files created are added in same folder.
    The files are containing those records which match the condition i.e. = Mid(Cells(r, "A"), 35, 3)
    Means if 3 characters are matched records must be stored in that file only.
    code create different files as per our requirement.

    The following code works perfectly but If again run macro the file appended with duplicate record, so I want that if file already created then msg must be 'File already exist'
    Else
    Can we overwrite the above files if we again Run the macro without passing any message to avoid record duplication.

    Alphafrog your code is checking every record & showing file already exist which is time consuming & thanks for the same.

    Mohan_r1980 your code creates only single file for all records which is not useful for me but it is avoiding duplication is most perfect & thanks for the same.

    Please Login or Register  to view this content.
    Last edited by sanjuss2; 12-28-2018 at 01:04 AM. Reason: attachment add

  8. #8
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Stop appending record in text file

    Try Below Code
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    12-03-2014
    Location
    India
    MS-Off Ver
    2016 .......
    Posts
    390

    Re: Stop appending record in text file

    Your code create folder then file after click on button twice.
    There is not record in the file
    No separate file create for the mid field i.e. 35,3

    I want separate file of same number

  10. #10
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Stop appending record in text file

    show your dummy output

    means
    dummy text files which you want to create
    data which you want to write in text file.

  11. #11
    Forum Contributor
    Join Date
    12-03-2014
    Location
    India
    MS-Off Ver
    2016 .......
    Posts
    390

    Re: Stop appending record in text file

    Hi
    Please find attachments of output of text files. which contains the records.
    the files are stored in folder name 25122018

    I have used following code

    Please Login or Register  to view this content.
    If I run again this macro then duplicate records will be added in file.... I want to stop that duplication
    Attached Files Attached Files
    Last edited by sanjuss2; 12-28-2018 at 07:39 AM.

  12. #12
    Forum Contributor
    Join Date
    12-03-2014
    Location
    India
    MS-Off Ver
    2016 .......
    Posts
    390

    Re: Stop appending record in text file

    Hi all,
    I Can use 2 macros if available
    1. for creation of file
    2. for stop duplication

    If anyone have such kindly suggest

  13. #13
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Stop appending record in text file

    Hi
    try
    Please Login or Register  to view this content.
    this is for creation of files
    wait for duplicate checking i am busy today, may be some one help
    Last edited by mohan.r1980; 12-29-2018 at 04:11 AM.

  14. #14
    Forum Contributor
    Join Date
    12-03-2014
    Location
    India
    MS-Off Ver
    2016 .......
    Posts
    390

    Re: Stop appending record in text file

    hi mohan.r1980

    Thanks for co-operation.

    actually the code which I have already specified is also given the same result & I am seeking guidance on 'NO duplicate record should be added after creation of file'.

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,456

    Re: Stop appending record in text file

    The the arguments for the Open keyword.
    https://docs.microsoft.com/en-gb/off...open-statement

    In all the code examples you are using the Append method, which is what you say you don't want.
    Try using Output rather than Append.
    Cheers
    Andy
    www.andypope.info

  16. #16
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Stop appending record in text file

    Hi Sanju,
    try below script which is combination of both requirement
    Please Login or Register  to view this content.
    Last edited by mohan.r1980; 12-29-2018 at 05:54 AM. Reason: attaching file also

  17. #17
    Forum Contributor
    Join Date
    12-03-2014
    Location
    India
    MS-Off Ver
    2016 .......
    Posts
    390

    Re: Stop appending record in text file

    So excellent....
    Thanks very much

  18. #18
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Stop appending record in text file

    Your welcome and thanks for rep++

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. When downloading a text file how do I stop the request for the file name?
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2017, 04:58 AM
  2. [SOLVED] How Do I Stop A Text File Import From Converting to a Date?
    By jayclinton in forum Excel General
    Replies: 2
    Last Post: 05-04-2017, 01:59 PM
  3. appending a text file from the same folder where excel file is located
    By np1966 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2017, 10:11 PM
  4. import text file with 2 rows per record into 1 row
    By kblinkhorn in forum Excel General
    Replies: 2
    Last Post: 01-10-2013, 11:42 AM
  5. Text file appending
    By domex in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-16-2010, 04:02 AM
  6. appending line to text file
    By lif in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-02-2006, 08:23 PM
  7. Macro Record Stop Button
    By Patrick Simonds in forum Excel General
    Replies: 2
    Last Post: 07-31-2005, 02:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1