Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: saving file over existing file

    Here is my code, that blows up if the file already is there

    strsQL = "SELECT * INTO [Excel 8.0;DATABASE=" & FileName & "].[Worksheet1] FROM [" & TableQueryName & "];"
    DoCmd.SetWarnings False
    DoCmd.RunSQL strsQL, False

    how do i make it so i over rite the file or delete the file if it exists?

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Rename/Delete the file first.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    use error trapping
    try to open the file
    if it already exists consider offering the user the chance to use a new name, or consider the option of renaming the file or deleting it
    remove that particular error trapping set
    then write to your file.


    ...sounds dumb but remember to turn warning back on as soon as you have finished the section that you wanted the warnings off on.. otherwise you could spend hours tearing you hair out because you have switched off warnings.

  4. #4
    Join Date
    Oct 2003
    Posts
    233
    this is an auto run job in the middle of the night and weekends, i can't use msg boxes.

    I need to either delete the existing file, or use diff name on the new file like appending 2, or save over the existing file

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ......so you need to decide what your default actions are

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Kill <pathtofile> will delete the file.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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