Export from Access Creates new Worksheet instead of Updating (1 Viewer)

proballin

Registered User.
Local time
Today, 17:22
Joined
Feb 18, 2008
Messages
105
I have a macro in Access that should update my worksheet called "Sum". However instead of updating the sheet it creates a new worksheet called "Sum1".

In Access I am using the TransferSpreadsheet operation for the Macro.

Any clue as to why it will not update the existing "Sum" worksheet but instead creates one called "Sum1"?
 

boblarson

Smeghead
Local time
Today, 15:22
Joined
Jan 12, 2001
Messages
32,059
TransferSpreadsheet does that. It creates a new sheet, so if there is one already with the name it would use, it creates one with an appended number on.

If you want to update an existing sheet, you should use Excel Object Programming like:
Code:
Dim appXL As Object
Dim xlWB As Object
Dim xlWS As Object

Set appXL = CreateObject("Excel.Application")
Set xlWB = appXL.Workbooks.Open("yourFileNameAndPathHere")

Set xlWS = xlWB.Worksheets("Sum")
...etc. and then you can either use a recordset to write out the values by iterating through, or use the xlWS.CopyFromRecordst rst code to do so.

See if that gets you on your way. If you need some extra help, take a look at this code of mine which exports using this method.
 

MailMan

Registered User.
Local time
Today, 18:22
Joined
Sep 7, 2007
Messages
20
I haven't tried this from a macro, but in VB if you let access create the worksheet the first time, it will overwrite the worksheet each time after that.
 

proballin

Registered User.
Local time
Today, 17:22
Joined
Feb 18, 2008
Messages
105
You are right MailMan...I did that and it all works out now. Thanks!
 

Users who are viewing this thread

Top Bottom