Method 'Execute' of object'_Connection'failed

J

jac007

The code below is what i'm running to export data from a table in access 2000
into Excel spreadsheets. The first part works fine, it creates the
spreadsheets, but the second part of the code is suppose to export the data
from the tables into the spreadsheets that were created. But I keep getting
the "Method 'Execute' of object'_Connection'failed" message. Can someone
please help. Thanks!

Sub CREATE_REPORT_FILES()

Dim rs3 As ADODB.Recordset
Dim strSQL As String
Dim strUser As String
Dim strFormat As String
Dim strSQL2 As String
Dim FullPathFileName As String

'*******************FILE LOCATION GOES HERE
*******************************************
FullPathFileName = "C:\Documents and Settings\c13912\My Documents\WORK
FILES\Reports.xls
'***************************************************************************************

TemplateFileName = Replace(FullPathFileName, ".xls", "_")
strSQL = "select distinct Team from Roster"
Set rs3 = New ADODB.Recordset
rs3.Open strSQL, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
Do Until rs3.EOF
strUser = rs3![TEAM]
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(FullPathFileName)
objExcel.Visible = False
objExcel.DisplayAlerts = False
objWorkbook.SaveCopyAs TemplateFileName & strUser & ".xls"
objExcel.Quit
Set objWorkbook = Nothing
rs3.MoveNext
Loop
rs3.Close
btn = MsgBox("finished creating report files", vbOKOnly)

End Sub
Sub CREATE_ROST()


Dim rs2 As ADODB.Recordset
Dim strSQL As String
Dim strUser As String
Dim strFormat As String
Dim strSQL2 As String

'*******************FILE LOCATION GOES HERE
*******************************************
FullPathFileName = "C:\Documents and Settings\c13912\My Documents\WORK
FILES\Reports.xls
'***************************************************************************************

TemplateFileName = Replace(FullPathFileName, ".xls", "_")
strSQL = "select distinct Team from Roster"
Set rs2 = New ADODB.Recordset
rs2.Open strSQL, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
Do Until rs2.EOF
strUser = rs2![TEAM]
strSQL2 = "select Players, Number, Apodo, Position from Roster"
CurrentProject.Connection.Execute strSQL2
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Reports_" &
strUser, TemplateFileName & ".xls", False, ""
rs2.MoveNext
Loop
rs2.Close
btn = MsgBox("finished exporting Roster", vbOKOnly)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top