Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-11-2008, 09:36 PM
=?Utf-8?B?U3RvY2t3ZWxsNDM=?=
 
Posts: n/a
Delete old information when transferring to excel

Hello,

I have several queries that with a click of a button transfers the data to
Excel and works fine. Here is the Code:

Private Sub cmdExportC_Click()
On Error GoTo Do_Nothing

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"qryprocstatus", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"qryregion", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"qrymonthenddetail", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"qrybankcenter", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"inventory", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"inventory_details", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"qryissues", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"qryerrorcode", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"qryissues", txtExportFileC
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
"qryerrorcode", txtExportFileC

MsgBox "The tables have been successfully exported to " & txtExportFileC
& "."

Exit Sub

Do_Nothing:
MsgBox "Export has failed. An error occurred or the user terminated the
operation."
End Sub

However, when I click the button to run the query again and put in a
different date range, it adds it to the old instead of replacing it. How can
I get the new information to overide the old or on the click somehow delete
the old to capture the new?

I have several queries set up but may not use them all so I comment some
out. I am still in the designing phase.

Thanks Folks!!!!
Reply With Quote
  #2 (permalink)  
Old 08-12-2008, 12:06 AM
Jeanette Cunningham
 
Posts: n/a
Re: Delete old information when transferring to excel

Hi
one way would be to check for any existing spreadsheets with the name
txtExportFileC and either delete them or rename them.
You could instead give a different name to your latest e xport by adding the
time and date to the name of the file each time you export.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

"Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
news:86AEB3F8-F107-49D3-A234-8050E311F8E5@microsoft.com...
> Hello,
>
> I have several queries that with a click of a button transfers the data to
> Excel and works fine. Here is the Code:
>
> Private Sub cmdExportC_Click()
> On Error GoTo Do_Nothing
>
> DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "qryprocstatus", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "qryregion", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "qrymonthenddetail", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "qrybankcenter", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "inventory", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "inventory_details", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "qryissues", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "qryerrorcode", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "qryissues", txtExportFileC
> 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> "qryerrorcode", txtExportFileC
>
> MsgBox "The tables have been successfully exported to " &
> txtExportFileC
> & "."
>
> Exit Sub
>
> Do_Nothing:
> MsgBox "Export has failed. An error occurred or the user terminated
> the
> operation."
> End Sub
>
> However, when I click the button to run the query again and put in a
> different date range, it adds it to the old instead of replacing it. How
> can
> I get the new information to overide the old or on the click somehow
> delete
> the old to capture the new?
>
> I have several queries set up but may not use them all so I comment some
> out. I am still in the designing phase.
>
> Thanks Folks!!!!



Reply With Quote
  #3 (permalink)  
Old 08-12-2008, 01:03 PM
=?Utf-8?B?U3RvY2t3ZWxsNDM=?=
 
Posts: n/a
Re: Delete old information when transferring to excel

Hi Jeanette,

Thanks for responding.

I understand changing the name but I don't want a lot of spreadsheets and
have to delete the sheets individually each time. I just want to click the
button and have the new export overwrite was is in the designated worksheet.
When importing from excel to access I can make a delete query but now I want
to go the other way. Does that make sense?

Thanks!!

"Jeanette Cunningham" wrote:

> Hi
> one way would be to check for any existing spreadsheets with the name
> txtExportFileC and either delete them or rename them.
> You could instead give a different name to your latest e xport by adding the
> time and date to the name of the file each time you export.
>
>
> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
>
> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
> news:86AEB3F8-F107-49D3-A234-8050E311F8E5@microsoft.com...
> > Hello,
> >
> > I have several queries that with a click of a button transfers the data to
> > Excel and works fine. Here is the Code:
> >
> > Private Sub cmdExportC_Click()
> > On Error GoTo Do_Nothing
> >
> > DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "qryprocstatus", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "qryregion", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "qrymonthenddetail", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "qrybankcenter", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "inventory", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "inventory_details", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "qryissues", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "qryerrorcode", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "qryissues", txtExportFileC
> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> > "qryerrorcode", txtExportFileC
> >
> > MsgBox "The tables have been successfully exported to " &
> > txtExportFileC
> > & "."
> >
> > Exit Sub
> >
> > Do_Nothing:
> > MsgBox "Export has failed. An error occurred or the user terminated
> > the
> > operation."
> > End Sub
> >
> > However, when I click the button to run the query again and put in a
> > different date range, it adds it to the old instead of replacing it. How
> > can
> > I get the new information to overide the old or on the click somehow
> > delete
> > the old to capture the new?
> >
> > I have several queries set up but may not use them all so I comment some
> > out. I am still in the designing phase.
> >
> > Thanks Folks!!!!

>
>
>

Reply With Quote
  #4 (permalink)  
Old 08-12-2008, 01:43 PM
Douglas J. Steele
 
Posts: n/a
Re: Delete old information when transferring to excel

How about code that looks in the workbook for a worksheet of a given name
and deletes it if it exists?

Something like:

Sub DeleteWorksheet( _
WorkbookName As String, _
WorksheetName As String _
)

On Error GoTo ErrHandler

Dim objExcel As Object

If Len(Dir(WorkbookName)) > 0 Then
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open WorkbookName
objExcel.ActiveWorkbook.Worksheets(WorksheetName). Delete
objExcel.ActiveWorkbook.Close SaveChanges:=True
objExcel.Application.Quit
Set objExcel = Nothing
End If

EndIt:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 9 ' Subscript out of range: worksheet doesn't exist
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
Resume EndIt
End Select

End Sub

You'd use this as

DeleteWorksheet txtExportFileC, "qryprocstatus"

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
news:5BF564FD-3BBA-49B7-B2E1-06123878454C@microsoft.com...
> Hi Jeanette,
>
> Thanks for responding.
>
> I understand changing the name but I don't want a lot of spreadsheets and
> have to delete the sheets individually each time. I just want to click the
> button and have the new export overwrite was is in the designated
> worksheet.
> When importing from excel to access I can make a delete query but now I
> want
> to go the other way. Does that make sense?
>
> Thanks!!
>
> "Jeanette Cunningham" wrote:
>
>> Hi
>> one way would be to check for any existing spreadsheets with the name
>> txtExportFileC and either delete them or rename them.
>> You could instead give a different name to your latest e xport by adding
>> the
>> time and date to the name of the file each time you export.
>>
>>
>> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
>>
>> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
>> news:86AEB3F8-F107-49D3-A234-8050E311F8E5@microsoft.com...
>> > Hello,
>> >
>> > I have several queries that with a click of a button transfers the data
>> > to
>> > Excel and works fine. Here is the Code:
>> >
>> > Private Sub cmdExportC_Click()
>> > On Error GoTo Do_Nothing
>> >
>> > DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "qryprocstatus", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "qryregion", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "qrymonthenddetail", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "qrybankcenter", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "inventory", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "inventory_details", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "qryissues", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "qryerrorcode", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "qryissues", txtExportFileC
>> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> > "qryerrorcode", txtExportFileC
>> >
>> > MsgBox "The tables have been successfully exported to " &
>> > txtExportFileC
>> > & "."
>> >
>> > Exit Sub
>> >
>> > Do_Nothing:
>> > MsgBox "Export has failed. An error occurred or the user terminated
>> > the
>> > operation."
>> > End Sub
>> >
>> > However, when I click the button to run the query again and put in a
>> > different date range, it adds it to the old instead of replacing it.
>> > How
>> > can
>> > I get the new information to overide the old or on the click somehow
>> > delete
>> > the old to capture the new?
>> >
>> > I have several queries set up but may not use them all so I comment
>> > some
>> > out. I am still in the designing phase.
>> >
>> > Thanks Folks!!!!

>>
>>
>>



Reply With Quote
  #5 (permalink)  
Old 08-12-2008, 02:32 PM
=?Utf-8?B?U3RvY2t3ZWxsNDM=?=
 
Posts: n/a
Re: Delete old information when transferring to excel

Hi Doug,

Thanks for responding.

I must have done something wrong. I placed your code above mine for
transferring the query and when I click the button I get an Compile Error
"Expected End Sub" and this is highlighted in yellow:

Private Sub cmdExportA_Click()

Was I suppose to use a Module instead?

Thanks!!

"Douglas J. Steele" wrote:

> How about code that looks in the workbook for a worksheet of a given name
> and deletes it if it exists?
>
> Something like:
>
> Sub DeleteWorksheet( _
> WorkbookName As String, _
> WorksheetName As String _
> )
>
> On Error GoTo ErrHandler
>
> Dim objExcel As Object
>
> If Len(Dir(WorkbookName)) > 0 Then
> Set objExcel = CreateObject("Excel.Application")
> objExcel.Workbooks.Open WorkbookName
> objExcel.ActiveWorkbook.Worksheets(WorksheetName). Delete
> objExcel.ActiveWorkbook.Close SaveChanges:=True
> objExcel.Application.Quit
> Set objExcel = Nothing
> End If
>
> EndIt:
> Exit Sub
>
> ErrHandler:
> Select Case Err.Number
> Case 9 ' Subscript out of range: worksheet doesn't exist
> Resume Next
> Case Else
> MsgBox Err.Number & ": " & Err.Description
> Resume EndIt
> End Select
>
> End Sub
>
> You'd use this as
>
> DeleteWorksheet txtExportFileC, "qryprocstatus"
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
> news:5BF564FD-3BBA-49B7-B2E1-06123878454C@microsoft.com...
> > Hi Jeanette,
> >
> > Thanks for responding.
> >
> > I understand changing the name but I don't want a lot of spreadsheets and
> > have to delete the sheets individually each time. I just want to click the
> > button and have the new export overwrite was is in the designated
> > worksheet.
> > When importing from excel to access I can make a delete query but now I
> > want
> > to go the other way. Does that make sense?
> >
> > Thanks!!
> >
> > "Jeanette Cunningham" wrote:
> >
> >> Hi
> >> one way would be to check for any existing spreadsheets with the name
> >> txtExportFileC and either delete them or rename them.
> >> You could instead give a different name to your latest e xport by adding
> >> the
> >> time and date to the name of the file each time you export.
> >>
> >>
> >> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
> >>
> >> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
> >> news:86AEB3F8-F107-49D3-A234-8050E311F8E5@microsoft.com...
> >> > Hello,
> >> >
> >> > I have several queries that with a click of a button transfers the data
> >> > to
> >> > Excel and works fine. Here is the Code:
> >> >
> >> > Private Sub cmdExportC_Click()
> >> > On Error GoTo Do_Nothing
> >> >
> >> > DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "qryprocstatus", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "qryregion", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "qrymonthenddetail", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "qrybankcenter", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "inventory", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "inventory_details", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "qryissues", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "qryerrorcode", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "qryissues", txtExportFileC
> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> > "qryerrorcode", txtExportFileC
> >> >
> >> > MsgBox "The tables have been successfully exported to " &
> >> > txtExportFileC
> >> > & "."
> >> >
> >> > Exit Sub
> >> >
> >> > Do_Nothing:
> >> > MsgBox "Export has failed. An error occurred or the user terminated
> >> > the
> >> > operation."
> >> > End Sub
> >> >
> >> > However, when I click the button to run the query again and put in a
> >> > different date range, it adds it to the old instead of replacing it.
> >> > How
> >> > can
> >> > I get the new information to overide the old or on the click somehow
> >> > delete
> >> > the old to capture the new?
> >> >
> >> > I have several queries set up but may not use them all so I comment
> >> > some
> >> > out. I am still in the designing phase.
> >> >
> >> > Thanks Folks!!!!
> >>
> >>
> >>

>
>
>

Reply With Quote
  #6 (permalink)  
Old 08-12-2008, 02:50 PM
Douglas J. Steele
 
Posts: n/a
Re: Delete old information when transferring to excel

The sub could go in a stand-alone module (in which case it could be called
from any form in your application). It could also go into the class module
associated with your form.

It sounds as though you might have just tried copying the sub inside your
existing sub. If you're putting it into the form's class module, it needs to
be outside of all existing subs (and functions).

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
news:B37731E2-FE81-4EC4-B31C-16DA24521E69@microsoft.com...
> Hi Doug,
>
> Thanks for responding.
>
> I must have done something wrong. I placed your code above mine for
> transferring the query and when I click the button I get an Compile Error
> "Expected End Sub" and this is highlighted in yellow:
>
> Private Sub cmdExportA_Click()
>
> Was I suppose to use a Module instead?
>
> Thanks!!
>
> "Douglas J. Steele" wrote:
>
>> How about code that looks in the workbook for a worksheet of a given name
>> and deletes it if it exists?
>>
>> Something like:
>>
>> Sub DeleteWorksheet( _
>> WorkbookName As String, _
>> WorksheetName As String _
>> )
>>
>> On Error GoTo ErrHandler
>>
>> Dim objExcel As Object
>>
>> If Len(Dir(WorkbookName)) > 0 Then
>> Set objExcel = CreateObject("Excel.Application")
>> objExcel.Workbooks.Open WorkbookName
>> objExcel.ActiveWorkbook.Worksheets(WorksheetName). Delete
>> objExcel.ActiveWorkbook.Close SaveChanges:=True
>> objExcel.Application.Quit
>> Set objExcel = Nothing
>> End If
>>
>> EndIt:
>> Exit Sub
>>
>> ErrHandler:
>> Select Case Err.Number
>> Case 9 ' Subscript out of range: worksheet doesn't exist
>> Resume Next
>> Case Else
>> MsgBox Err.Number & ": " & Err.Description
>> Resume EndIt
>> End Select
>>
>> End Sub
>>
>> You'd use this as
>>
>> DeleteWorksheet txtExportFileC, "qryprocstatus"
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
>> news:5BF564FD-3BBA-49B7-B2E1-06123878454C@microsoft.com...
>> > Hi Jeanette,
>> >
>> > Thanks for responding.
>> >
>> > I understand changing the name but I don't want a lot of spreadsheets
>> > and
>> > have to delete the sheets individually each time. I just want to click
>> > the
>> > button and have the new export overwrite was is in the designated
>> > worksheet.
>> > When importing from excel to access I can make a delete query but now I
>> > want
>> > to go the other way. Does that make sense?
>> >
>> > Thanks!!
>> >
>> > "Jeanette Cunningham" wrote:
>> >
>> >> Hi
>> >> one way would be to check for any existing spreadsheets with the name
>> >> txtExportFileC and either delete them or rename them.
>> >> You could instead give a different name to your latest e xport by
>> >> adding
>> >> the
>> >> time and date to the name of the file each time you export.
>> >>
>> >>
>> >> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
>> >>
>> >> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
>> >> news:86AEB3F8-F107-49D3-A234-8050E311F8E5@microsoft.com...
>> >> > Hello,
>> >> >
>> >> > I have several queries that with a click of a button transfers the
>> >> > data
>> >> > to
>> >> > Excel and works fine. Here is the Code:
>> >> >
>> >> > Private Sub cmdExportC_Click()
>> >> > On Error GoTo Do_Nothing
>> >> >
>> >> > DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "qryprocstatus", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "qryregion", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "qrymonthenddetail", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "qrybankcenter", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "inventory", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "inventory_details", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "qryissues", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "qryerrorcode", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "qryissues", txtExportFileC
>> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
>> >> > "qryerrorcode", txtExportFileC
>> >> >
>> >> > MsgBox "The tables have been successfully exported to " &
>> >> > txtExportFileC
>> >> > & "."
>> >> >
>> >> > Exit Sub
>> >> >
>> >> > Do_Nothing:
>> >> > MsgBox "Export has failed. An error occurred or the user
>> >> > terminated
>> >> > the
>> >> > operation."
>> >> > End Sub
>> >> >
>> >> > However, when I click the button to run the query again and put in a
>> >> > different date range, it adds it to the old instead of replacing it.
>> >> > How
>> >> > can
>> >> > I get the new information to overide the old or on the click somehow
>> >> > delete
>> >> > the old to capture the new?
>> >> >
>> >> > I have several queries set up but may not use them all so I comment
>> >> > some
>> >> > out. I am still in the designing phase.
>> >> >
>> >> > Thanks Folks!!!!
>> >>
>> >>
>> >>

>>
>>
>>



Reply With Quote
  #7 (permalink)  
Old 08-12-2008, 03:00 PM
=?Utf-8?B?U3RvY2t3ZWxsNDM=?=
 
Posts: n/a
Re: Delete old information when transferring to excel

You were right, I pasted it in my existing sub.

I put it in a Stand alone module and works fine, my bad.

Thank you Sir! As always you're help is most appreciated!!

"Douglas J. Steele" wrote:

> The sub could go in a stand-alone module (in which case it could be called
> from any form in your application). It could also go into the class module
> associated with your form.
>
> It sounds as though you might have just tried copying the sub inside your
> existing sub. If you're putting it into the form's class module, it needs to
> be outside of all existing subs (and functions).
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
> news:B37731E2-FE81-4EC4-B31C-16DA24521E69@microsoft.com...
> > Hi Doug,
> >
> > Thanks for responding.
> >
> > I must have done something wrong. I placed your code above mine for
> > transferring the query and when I click the button I get an Compile Error
> > "Expected End Sub" and this is highlighted in yellow:
> >
> > Private Sub cmdExportA_Click()
> >
> > Was I suppose to use a Module instead?
> >
> > Thanks!!
> >
> > "Douglas J. Steele" wrote:
> >
> >> How about code that looks in the workbook for a worksheet of a given name
> >> and deletes it if it exists?
> >>
> >> Something like:
> >>
> >> Sub DeleteWorksheet( _
> >> WorkbookName As String, _
> >> WorksheetName As String _
> >> )
> >>
> >> On Error GoTo ErrHandler
> >>
> >> Dim objExcel As Object
> >>
> >> If Len(Dir(WorkbookName)) > 0 Then
> >> Set objExcel = CreateObject("Excel.Application")
> >> objExcel.Workbooks.Open WorkbookName
> >> objExcel.ActiveWorkbook.Worksheets(WorksheetName). Delete
> >> objExcel.ActiveWorkbook.Close SaveChanges:=True
> >> objExcel.Application.Quit
> >> Set objExcel = Nothing
> >> End If
> >>
> >> EndIt:
> >> Exit Sub
> >>
> >> ErrHandler:
> >> Select Case Err.Number
> >> Case 9 ' Subscript out of range: worksheet doesn't exist
> >> Resume Next
> >> Case Else
> >> MsgBox Err.Number & ": " & Err.Description
> >> Resume EndIt
> >> End Select
> >>
> >> End Sub
> >>
> >> You'd use this as
> >>
> >> DeleteWorksheet txtExportFileC, "qryprocstatus"
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no e-mails, please!)
> >>
> >>
> >> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
> >> news:5BF564FD-3BBA-49B7-B2E1-06123878454C@microsoft.com...
> >> > Hi Jeanette,
> >> >
> >> > Thanks for responding.
> >> >
> >> > I understand changing the name but I don't want a lot of spreadsheets
> >> > and
> >> > have to delete the sheets individually each time. I just want to click
> >> > the
> >> > button and have the new export overwrite was is in the designated
> >> > worksheet.
> >> > When importing from excel to access I can make a delete query but now I
> >> > want
> >> > to go the other way. Does that make sense?
> >> >
> >> > Thanks!!
> >> >
> >> > "Jeanette Cunningham" wrote:
> >> >
> >> >> Hi
> >> >> one way would be to check for any existing spreadsheets with the name
> >> >> txtExportFileC and either delete them or rename them.
> >> >> You could instead give a different name to your latest e xport by
> >> >> adding
> >> >> the
> >> >> time and date to the name of the file each time you export.
> >> >>
> >> >>
> >> >> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
> >> >>
> >> >> "Stockwell43" <Stockwell43@discussions.microsoft.com> wrote in message
> >> >> news:86AEB3F8-F107-49D3-A234-8050E311F8E5@microsoft.com...
> >> >> > Hello,
> >> >> >
> >> >> > I have several queries that with a click of a button transfers the
> >> >> > data
> >> >> > to
> >> >> > Excel and works fine. Here is the Code:
> >> >> >
> >> >> > Private Sub cmdExportC_Click()
> >> >> > On Error GoTo Do_Nothing
> >> >> >
> >> >> > DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "qryprocstatus", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "qryregion", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "qrymonthenddetail", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "qrybankcenter", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "inventory", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "inventory_details", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "qryissues", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "qryerrorcode", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "qryissues", txtExportFileC
> >> >> > 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7,
> >> >> > "qryerrorcode", txtExportFileC
> >> >> >
> >> >> > MsgBox "The tables have been successfully exported to " &
> >> >> > txtExportFileC
> >> >> > & "."
> >> >> >
> >> >> > Exit Sub
> >> >> >
> >> >> > Do_Nothing:
> >> >> > MsgBox "Export has failed. An error occurred or the user
> >> >> > terminated
> >> >> > the
> >> >> > operation."
> >> >> > End Sub
> >> >> >
> >> >> > However, when I click the button to run the query again and put in a
> >> >> > different date range, it adds it to the old instead of replacing it.
> >> >> > How
> >> >> > can
> >> >> > I get the new information to overide the old or on the click somehow
> >> >> > delete
> >> >> > the old to capture the new?
> >> >> >
> >> >> > I have several queries set up but may not use them all so I comment
> >> >> > some
> >> >> > out. I am still in the designing phase.
> >> >> >
> >> >> > Thanks Folks!!!!
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:56 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Job Listing | Babb Fest | Credit Card | Advertising | Online Loans



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114