PDA

View Full Version : Overwriting Worksheet



bee
07-02-2008, 08:55 PM
I'm using MS Access 2000 to write this program. I'm trying to create a worksheet with the name "Within CMB2" from an existing workbook. The thing is, the program only runs when there is no existing file. I want the program to overwrite the worksheet "Within CMB2" if it already exists. Normally, the program will start without the "Within CMB2" worksheet. It will start by adding it. However, I want the program to be able to overwrite it with the same name if it already exists.

The error message that it displays is Run-time error '1004': Cannot rename a sheet to the same name as another sheet, a referenced object library or a workbook referenced by Visual Basic.

Thank you so much for looking into my code.

CreganTur
07-03-2008, 04:44 AM
Take a look at this link:http://www.tek-tips.com/faqs.cfm?fid=4116

It reviews how to tell if a file exists, and it also has a method for deleting a file. This means you can check to see if the file already exists, and if it does then delete it so that you can create a new file.

bee
07-06-2008, 09:03 PM
Take a look at this link:http://www.tek-tips.com/faqs.cfm?fid=4116

It reviews how to tell if a file exists, and it also has a method for deleting a file. This means you can check to see if the file already exists, and if it does then delete it so that you can create a new file.


Thanks for the suggestion, Randy. However, the link that you gave me only checks if the file exists. I want to check if the worksheet exists and if it does, it overwrites it. :) I don't want it to prompt me if I want to overwrite it. I want it to automatically overwrite.

OBP
07-07-2008, 02:46 AM
bee, I can see that this is related to your other post.
You can find the names of the worksheets, once you have found if it exists you can either leave it in place and remove the data and write new data to it.
Or delete the Worksheet and then recreate it with the new data.

ps but I still don't understand why :dunno

bee
07-07-2008, 08:57 AM
bee, I can see that this is related to your other post.
You can find the names of the worksheets, once you have found if it exists you can either leave it in place and remove the data and write new data to it.
Or delete the Worksheet and then recreate it with the new data.

ps but I still don't understand why :dunno

how do i find the names of the worksheet? :) i'm actually doing this because when the user tries to click on the browse button and runs the program again, i want the existing worksheet to be overwritten. :) it displays an error when there's already an existing