PC Review


Reply
Thread Tools Rate Thread

Creates table instead of exporting data

 
 
=?Utf-8?B?SlQ=?=
Guest
Posts: n/a
 
      17th Mar 2006
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data from a different table Alimbilo Microsoft Access Getting Started 2 21st May 2008 05:17 PM
Creates table instead of exporting to Excel issue =?Utf-8?B?SlQ=?= Microsoft Access VBA Modules 4 20th Mar 2006 09:40 PM
Exporting to Excel creates single quote in front of data =?Utf-8?B?QWxleA==?= Microsoft Access 5 25th Oct 2004 11:42 AM
Exporting data from a table to a CSV formatted via another DB/table =?Utf-8?B?QnJhZCBFY2s=?= Microsoft Access External Data 11 24th Dec 2003 11:28 PM
Make Table Query Creates Binary Data Type Bill Microsoft Access 1 9th Aug 2003 01:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:46 AM.