S
Steven
I am trying to export using a SELECT statment and if returns "Too few
parameters, expected 4". I am pretty sure the SELECT statment is ok. I have
tested it in a query. What am I doing wrong.
Thank you,
Steven
Sub Export()
On Error GoTo ExportBatch_Err
Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Dim strSQL As String
strSQL = "SELECT [SM&R].Co, [SM&R].Account, Sum([SM&R].Amount) AS
SumOfAmount, ChartOfAccounts.FSCategory " + _
"FROM [SM&R] LEFT JOIN ChartOfAccounts ON ([SM&R].Account =
ChartOfAccounts.Account) AND ([SM&R].Co = ChartOfAccounts.Co) " + _
"WHERE ((([SM&R].Period) <= [Forms]![FLeadLookup]![Combo42])) " + _
"GROUP BY [SM&R].Co, [SM&R].Account, ChartOfAccounts.FSCategory " + _
"HAVING ((([SM&R].Co)=[Forms]![FLeadLookup]![Co]) AND
(([SM&R].Account) Between [Forms]![FLeadLookup]![Text0] And
[Forms]![FLeadLookup]![Combo19]) AND ((Sum([SM&R].Amount))<>0)) " + _
"ORDER BY [SM&R].Co, [SM&R].Account"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If Dir("C:\My Documents\AcctBalances.xls") = "" Then
DoCmd.TransferSpreadsheet acExport, 8, rs, "C:\My
Documents\AcctBalances.xls", True, ""
MsgBox "Exported to C:\My Documents\AcctBalances.xls"
Else
If IsOpen("C:\My Documents\AcctBalances.xls") Then
MsgBox "File C:\My Documents\AcctBalances.xls is open." + Chr(13) +
Chr(13) + _
" Please close the file and try again."
Exit Sub
Else
DoCmd.TransferSpreadsheet acExport, 8, rs, "C:\My
Documents\AcctExport.xls", True, ""
MsgBox "Exported to C:\My Documents\AcctBalances.xls"
End If
End If
ExportBatch_Exit:
Exit Sub
ExportBatch_Err:
MsgBox Error$
Resume ExportBatch_Exit
End Sub
parameters, expected 4". I am pretty sure the SELECT statment is ok. I have
tested it in a query. What am I doing wrong.
Thank you,
Steven
Sub Export()
On Error GoTo ExportBatch_Err
Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Dim strSQL As String
strSQL = "SELECT [SM&R].Co, [SM&R].Account, Sum([SM&R].Amount) AS
SumOfAmount, ChartOfAccounts.FSCategory " + _
"FROM [SM&R] LEFT JOIN ChartOfAccounts ON ([SM&R].Account =
ChartOfAccounts.Account) AND ([SM&R].Co = ChartOfAccounts.Co) " + _
"WHERE ((([SM&R].Period) <= [Forms]![FLeadLookup]![Combo42])) " + _
"GROUP BY [SM&R].Co, [SM&R].Account, ChartOfAccounts.FSCategory " + _
"HAVING ((([SM&R].Co)=[Forms]![FLeadLookup]![Co]) AND
(([SM&R].Account) Between [Forms]![FLeadLookup]![Text0] And
[Forms]![FLeadLookup]![Combo19]) AND ((Sum([SM&R].Amount))<>0)) " + _
"ORDER BY [SM&R].Co, [SM&R].Account"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If Dir("C:\My Documents\AcctBalances.xls") = "" Then
DoCmd.TransferSpreadsheet acExport, 8, rs, "C:\My
Documents\AcctBalances.xls", True, ""
MsgBox "Exported to C:\My Documents\AcctBalances.xls"
Else
If IsOpen("C:\My Documents\AcctBalances.xls") Then
MsgBox "File C:\My Documents\AcctBalances.xls is open." + Chr(13) +
Chr(13) + _
" Please close the file and try again."
Exit Sub
Else
DoCmd.TransferSpreadsheet acExport, 8, rs, "C:\My
Documents\AcctExport.xls", True, ""
MsgBox "Exported to C:\My Documents\AcctBalances.xls"
End If
End If
ExportBatch_Exit:
Exit Sub
ExportBatch_Err:
MsgBox Error$
Resume ExportBatch_Exit
End Sub