trackstar2786
Registered User.
- Local time
- Today, 01:39
- Joined
- Sep 19, 2017
- Messages
- 11
Brand new, so please excuse my inexperience. I'm trying to do two things.
1) Using the Code below, I'm attempting to create a new excel sheet that isolate each account number and exports that account's summary to an excel sheet. I'm currently stuck either in my SQL or vba statement how to have it be dynamic and move down the list of account numbers. Otherwise the naming convention for excel works fine.
2) There is a detail tab that I would need to create/do the same extraction (except multiple lines) that has the same corresponding account number and place that detail in a second tab in the excel sheet that was created in the first portion.
Few issues when I run the below code:
1) It pulls all the accounts in the summary tab
2) the files save in my documents rather than the designated path.
3) I still need to do a breakout of a detail tab using the same corresponding account number and create/transfer it to a second sheet in the workbook
1) Using the Code below, I'm attempting to create a new excel sheet that isolate each account number and exports that account's summary to an excel sheet. I'm currently stuck either in my SQL or vba statement how to have it be dynamic and move down the list of account numbers. Otherwise the naming convention for excel works fine.
2) There is a detail tab that I would need to create/do the same extraction (except multiple lines) that has the same corresponding account number and place that detail in a second tab in the excel sheet that was created in the first portion.
Few issues when I run the below code:
1) It pulls all the accounts in the summary tab
2) the files save in my documents rather than the designated path.
3) I still need to do a breakout of a detail tab using the same corresponding account number and create/transfer it to a second sheet in the workbook
Code:
Private Sub BreakoutButton()
Dim qdf As DAO.QueryDef
For Each qdf In CurrentDb.QueryDefs
If qdf.Name = "Commission_Statement" Then
CurrentDb.QueryDefs.Delete "Commission_Statement"
Exit For
End If
Next
Dim rs As DAO.Recordset
Dim qdfnew As DAO.QueryDef
Dim strSQL As String
Dim Path As String
'Path to the folder for the file to export to
Path = "F:\Commission Statement\Test Output"
'"L:\AIDC PM\Activation Tracking\Carrier Commission Payment Statement\Commission Statement-Kevin"
With CurrentDb
Set rs = .OpenRecordset("ReportBreakout")
'Replace with name of the actual Account Table
rs.MoveFirst
'For each Account in the table
Do Until rs.EOF
strSQL = "Select Account, Reseller, ATTWireless, ATTWireline, Comcast, DataXoom, Spectrum, TMobile, TWC, VerizonWireless, VerizonWireline, Total FROM ReportBreakout WHERE Account=rs.account"
'NEED A VARIABLE or DYNAMIC WHERE CLAUSE
'createquerydef command line follows
Set qdfnew = .CreateQueryDef("Commission_Statement", strSQL)
DoEvents
'Based on exporting file for previous month on the agreed upon 12th day
'DoCmd.TransferSpreadsheet acOutputQuery, "Commission_Statement", acFormatXLS, rs!Account & "_" & rs!Reseller & " " & Format(Date - 16, "mmmm yyyy") & ".xls", False, "Sheet1"
'DoCmd.TransferSpreadsheet acOutputQuery, "Commission_Statement", acFormatXLS, rs!Account & "_" & rs!Reseller & " " & Format(Date - 16, "mmmm yyyy") & ".xls", False, "Sheet1"
DoCmd.OutputTo acOutputQuery, "Commission_Statement", acFormatXLS, rs!Account & "_" & rs!Reseller & " " & Format(Date - 16, "mmmm yyyy") & ".xls", False
'DoCmd.OutputTo acOutputQuery, "Commission_Statement", acFormatXLS, rs!Account & "_" & rs!Reseller & " " & Format(Date - 16, "mmmm yyyy") & ".xls", False, "Sheet2"
'export to a specific tab
'delete the temporay query
DoCmd.DeleteObject acQuery, "Commission_Statement"
Set qdfnew = Nothing
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End With
End Sub
Last edited: