Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default Creates table instead of exporting data

I have a macro that in Excel that I would like to do some things in Access
and then export the data to an Excel file. Following is the code I am
working with. The issue is the macro is trying to create a table in Access
instead of Excel. I have indicated the line of code where the issue occurs.
Any suggestions or help on how to resolve this issue would be appreciated.
Thanks.....

Dim QueryName As String
Set AccApp = GetObject(, "Access.Application")

QueryName = "Clear DeptID Data Table"
AccApp.DoCmd.OpenQuery QueryName

QueryName = "Create DeptID Reference"
AccApp.DoCmd.OpenQuery QueryName

QueryName = "Update US Detail Table"
AccApp.DoCmd.OpenQuery QueryName

** Executes Excel Code here **

Dim qry As QueryDef
Dim strGp As String
Dim rst As Recordset

Do Until Len(Cells(r, 1)) = 0

strGp = Cells(r, 1)

On Error Resume Next
AccApp.CurrentDb.QueryDefs.Delete ("Group" & strGp & " Detail file")
On Error GoTo 0
Set qry = AccApp.CurrentDb.CreateQueryDef("Group" & strGp & " Detail file")

qry.Sql = "SELECT Detail_US.* FROM Detail_US WHERE (((Detail_US.Region)= """
& strGp & """));"

Set rst = AccApp.CurrentDb.OpenRecordset(qry.Name)

If rst.RecordCount < 0 Then
TargetFile = "C:\Detail.xls"

** the next line of code tries to create a table in access instead of
exporting it to Excel**

AccApp.DoCmd.TransferSpreadsheet acExport, 8, "Group" & strGp & " Detail
file", TargetFile

End If

AccApp.CurrentDb.QueryDefs.Delete ("Group" & strGp & " Detail file")

r = r + 1

Loop

--
JT
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data from a table to blogs owen.cxy New Users to Excel 2 June 25th 09 07:30 AM
Exporting data to Excel pivot table from Access Pat Dools Excel Discussion (Misc queries) 3 October 22nd 08 06:49 PM
Pivot table creates blank table [email protected] Charts and Charting in Excel 2 October 17th 06 05:21 PM
Exporting data (Data Table) to Excel Vlash Excel Worksheet Functions 3 September 29th 06 09:52 PM
exporting summary data for pivot table! via135 Excel Worksheet Functions 2 February 2nd 06 06:16 PM


All times are GMT +1. The time now is 04:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"