Private Sub Command11_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim qdfCurr As DAO.QueryDef
Dim strFolder As String
Dim strSQL As String
strFolder = "T:\Access Testing"
Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT ACCT_TABLE.ID_1 FROM ACCT_TABLE WHERE (((ACCT_TABLE.ID_18) = [Forms]![Form2]![Text6])) GROUP BY ACCT_TABLE.ID_1")
Set qdfCurr = dbCurr.CreateQueryDef("qryTemp")
Do While rsCurr.EOF = False
qdfCurr.SQL = SELECT [Qry(a)].ID_1, [Qry(a)].ID_10, [Qry(a)].ID_11, [Qry(a)].ACCT_ID, [Qry(a)].ID_8, [Qry(a)].ID_22, [Qry(a)].ID_5, [Qry(a)].SumOfVOLUMES AS Nov, [Qry(b)].SumOfVOLUMES AS [Dec], [Qry(a)]!SumOfVOLUMES-[Qry(b)]!SumOfVOLUMES AS Movement FROM [Qry(a)] INNER JOIN [Qry(b)] ON ([Qry(a)].ACCT_ID = [Qry(b)].ACCT_ID) AND ([Qry(a)].ID_1 = [Qry(b)].ID_1) GROUP BY [Qry(a)].ID_1, [Qry(a)].ID_10, [Qry(a)].ID_11, [Qry(a)].ACCT_ID, [Qry(a)].ID_8, [Qry(a)].ID_22, [Qry(a)].ID_5, [Qry(a)].SumOfVOLUMES, [Qry(b)].SumOfVOLUMES, [Qry_Large Movements(a)]!SumOfVOLUMES-[Qry(b)]!SumOfVOLUMES WHERE Qry(a)].ID_1 = '" & rsCurr! ACCT_TABLE.ID_1 & "'
qdfCurr.Close
DoCmd.TransferSpreadsheet acExport, , "qryTemp", strFolder & "Details for " & rsCurr!ACCT_TABLE.ID_1 & ".xls", True
rsCurr.MoveNext
Loop
rsCurr.Close
Set rsCurr = Nothing
Set qdfCurr = Nothing
Set dbCurr = Nothing
End Sub
|