I don't understand what you mean by "break point". Can you explain further?
Option Compare Database
Private Sub cmdExport_Click()
Dim xlapp As Excel.Application
Dim wb As Excel.workbook
Dim ws As Excel.worksheet
Dim rs As Recordset
Dim strSQL As String
Dim strVolCat As String
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
Case "1A"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
strVolCat = "1A"[COLOR="Red"]
strSQL = "SELECT DefineCPMVolCatByCustomer.ParentTieID, DefineCPMVolCatByCustomer.Customer, DefineCPMVolCatByCustomer.Volume, DefineCPMVolCatByCustomer.GrossPerTon, DefineCPMVolCatByCustomer.GrossSales, DefineCPMVolCatByCustomer.GTNPerTon, DefineCPMVolCatByCustomer.GTNSales, DefineCPMVolCatByCustomer.PricePerTon, DefineCPMVolCatByCustomer.NetSales, DefineCPMVolCatByCustomer.COGSPerTon, DefineCPMVolCatByCustomer.COGS, DefineCPMVolCatByCustomer.MarginSales, DefineCPMVolCatByCustomer.MarginPerTon, DefineCPMVolCatByCustomer.MarginPct FROM DefineCPMVolCatByCustomer Where VolCat = '" & strVolCat & "'"[/COLOR]
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
End Select
Set rs = Nothing
Set ws = Nothing
Set wb = Nothing
Set xlapp = Nothing
End Sub
Hello All,
I am very sorry for being difficult, but I have no idea how to see the values of my variables the way you are describing to me. I do see that the strSQL variable is trying to be set before the strVolCat value is set, could this be the problem?
Maybe my code should be as follows:
Code:Option Compare Database Private Sub cmdExport_Click() Dim xlapp As Excel.Application Dim wb As Excel.workbook Dim ws As Excel.worksheet Dim rs As Recordset Dim strSQL As String Dim strVolCat As String Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94] Case "1A" Set xlapp = New Excel.Application Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm") Set ws = wb.worksheets("1A") strVolCat = "1A"[COLOR="Red"] strSQL = "SELECT DefineCPMVolCatByCustomer.ParentTieID, DefineCPMVolCatByCustomer.Customer, DefineCPMVolCatByCustomer.Volume, DefineCPMVolCatByCustomer.GrossPerTon, DefineCPMVolCatByCustomer.GrossSales, DefineCPMVolCatByCustomer.GTNPerTon, DefineCPMVolCatByCustomer.GTNSales, DefineCPMVolCatByCustomer.PricePerTon, DefineCPMVolCatByCustomer.NetSales, DefineCPMVolCatByCustomer.COGSPerTon, DefineCPMVolCatByCustomer.COGS, DefineCPMVolCatByCustomer.MarginSales, DefineCPMVolCatByCustomer.MarginPerTon, DefineCPMVolCatByCustomer.MarginPct FROM DefineCPMVolCatByCustomer Where VolCat = '" & strVolCat & "'"[/COLOR] Set rs = CurrentDb.OpenRecordset(strSQL) ws.range("A2").copyfromrecordset rs xlapp.Visible = True xlapp.Dialogs(xlDialogSaveAs).Show End Select Set rs = Nothing Set ws = Nothing Set wb = Nothing Set xlapp = Nothing End Sub
[SIZE="2"]Option Compare Database
Private Sub cmdExport_Click()
Dim xlapp As Excel.Application
Dim wb As Excel.workbook
Dim ws As Excel.worksheet
Dim rs As Recordset
Dim strSQL As String
Dim strVolCat As String
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
Case "1A"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
strVolCat = "1A"
strSQL = "SELECT DefineCPMVolCatByCustomer.ParentTieID, DefineCPMVolCatByCustomer.Customer, DefineCPMVolCatByCustomer.Volume, DefineCPMVolCatByCustomer.GrossPerTon, DefineCPMVolCatByCustomer.GrossSales, DefineCPMVolCatByCustomer.GTNPerTon, DefineCPMVolCatByCustomer.GTNSales, DefineCPMVolCatByCustomer.PricePerTon, DefineCPMVolCatByCustomer.NetSales, DefineCPMVolCatByCustomer.COGSPerTon, DefineCPMVolCatByCustomer.COGS, DefineCPMVolCatByCustomer.MarginSales, DefineCPMVolCatByCustomer.MarginPerTon, DefineCPMVolCatByCustomer.MarginPct FROM DefineCPMVolCatByCustomer Where VolCat = '" & strVolCat & "'"
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
End Select
Set rs = Nothing
Set ws = Nothing
Set wb = Nothing
Set xlapp = Nothing
End Sub[/SIZE]
Option Compare Database
Private Sub cmdExport_Click()
Dim xlapp As Excel.Application
Dim wb As Excel.workbook
Dim ws As Excel.worksheet
Dim rs As Recordset
Dim strSQL As String
Dim strVolCat As String
strSQL = "SELECT DefineCPMVolCatByCustomer.ParentTieID, DefineCPMVolCatByCustomer.Customer, DefineCPMVolCatByCustomer.Volume, DefineCPMVolCatByCustomer.GrossPerTon, DefineCPMVolCatByCustomer.GrossSales, DefineCPMVolCatByCustomer.GTNPerTon, DefineCPMVolCatByCustomer.GTNSales, DefineCPMVolCatByCustomer.PricePerTon, DefineCPMVolCatByCustomer.NetSales, DefineCPMVolCatByCustomer.COGSPerTon, DefineCPMVolCatByCustomer.COGS, DefineCPMVolCatByCustomer.MarginSales, DefineCPMVolCatByCustomer.MarginPerTon, DefineCPMVolCatByCustomer.MarginPct FROM DefineCPMVolCatByCustomer Where VolCat = '" & strVolCat & "'"
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
Case "1A"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
strVolCat = "1A"
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
End Select
Set rs = Nothing
Set ws = Nothing
Set wb = Nothing
Set xlapp = Nothing
End Sub
Option Compare Database
Private Sub cmdExport_Click()
Dim xlapp As Excel.Application
Dim wb As Excel.workbook
Dim ws As Excel.worksheet
Dim rs As Recordset
Dim strSQL As String
Dim strVolCat As String
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
Case "1A"
strVolCat = "1A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1B"
strVolCat = "1B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1C"
strVolCat = "1C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1D"
strVolCat = "1D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2A"
strVolCat = "2A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2B"
strVolCat = "2B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2C"
strVolCat = "2C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2D"
strVolCat = "2D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case Else
strVolCat = "1A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
End Select
Set rs = Nothing
Set ws = Nothing
Set wb = Nothing
Set xlapp = Nothing
End Sub
Option Compare Database
Private Sub cmdExport_Click()
Dim xlapp As Excel.Application
Dim wb As Excel.workbook
Dim ws As Excel.worksheet
Dim rs As Recordset
Dim strSQL As String
Dim strVolCat As String
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Case "1A"
strVolCat = "1A"
Case "1B"
strVolCat = "1B"
Case "1C"
strVolCat = "1C"
Case "1D"
strVolCat = "1D"
Case "2A"
strVolCat = "2A"
Case "2B"
strVolCat = "2B"
Case "2C"
strVolCat = "2C"
Case "2D"
strVolCat = "2D"
Case Else ' Copy ALL
strVolCat = "1A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
GoTo ExitMySub
End Select
strSQL = strSQL & " Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
ExitMySub:
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Set rs = Nothing
Set ws = Nothing
Set wb = Nothing
Set xlapp = Nothing
End Sub
Private Sub cmdExport_Click()
Dim xlapp As Excel.Application
Dim wb As Excel.workbook
Dim ws As Excel.worksheet
Dim rs As Recordset
Dim strSQL As String
Dim strVolCat As String
Dim asRef(7) As String ' Array of 8 values (as - array string) - Added by MRdNk
Dim i As Integer ' integer used as a counter, for the array - added by MRdNk
Dim bCopyAll As Boolean ' True equals - Copy All
bCopyAll = False
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
'''''''''''''''''
''''MRdNk bit''''
'''''''''''''''''
asRef(0) = "A1"
asRef(1) = "A2"
asRef(2) = "A3"
asRef(3) = "A4"
asRef(4) = "B1"
asRef(5) = "B2"
asRef(6) = "B3"
asRef(7) = "A4"
Case "1A"
strVolCat = "1A"
Case "1B"
strVolCat = "1B"
Case "1C"
strVolCat = "1C"
Case "1D"
strVolCat = "1D"
Case "2A"
strVolCat = "2A"
Case "2B"
strVolCat = "2B"
Case "2C"
strVolCat = "2C"
Case "2D"
strVolCat = "2D"
Case Else ' Copy ALL
bCopyAll = True
For i = 0 To 7
If bCopyAll = True Then
If i = 0 Then
strVolCat = asRef(i)
Else
strVolCat = strVolCat & ", " & asRef(i)
End If
Else
i = 7
End If
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "'"
Set ws = wb.worksheets(strVolCat)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
Next i
bCopyAll = False
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Set rs = Nothing
Set ws = Nothing
Set wb = Nothing
Set xlapp = Nothing
End Sub
Option Compare Database
Private Sub cmdExport_Click()
Dim xlapp As Excel.Application
Dim wb As Excel.workbook
Dim ws As Excel.worksheet
Dim rs As Recordset
Dim strSQL As String
Dim strVolCat As String
[COLOR="Red"][B]Dim strCompany As String[/B][/COLOR]
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
Case "1A"
[COLOR="Red"][B]strCompany = "[Forms]![Frm-SelectCompanyVolCat]![Combo78]"[/B][/COLOR]
strVolCat = "1A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany [COLOR="Red"][B]Where VolumeCat = '" & strVolCat & "', Company = '" & strCompany & "'[/B][/COLOR] ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1B"
strVolCat = "1B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1C"
strVolCat = "1C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1D"
strVolCat = "1D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2A"
strVolCat = "2A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2B"
strVolCat = "2B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2C"
strVolCat = "2C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2D"
strVolCat = "2D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case Else
strVolCat = "1A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
End Select
Set rs = Nothing
Set ws = Nothing
Set wb = Nothing
Set xlapp = Nothing
End Sub
Option Compare Database
Private Sub cmdExport_Click()
'Backup 20081003
Dim xlapp As Excel.Application
Dim wb As Excel.workbook
Dim ws As Excel.worksheet
Dim rs As Recordset
Dim strSQL As String
Dim strVolCat As String
Dim strCompany As String
strCompany = [Forms]![Frm-SelectCompanyVolCat]![Combo78]
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
Case "1A"
strVolCat = "1A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1B"
strVolCat = "1B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1C"
strVolCat = "1C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "1D"
strVolCat = "1D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2A"
strVolCat = "2A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2B"
strVolCat = "2B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2C"
strVolCat = "2C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case "2D"
strVolCat = "2D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("2D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
Case Else
strVolCat = "1A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set xlapp = New Excel.Application
Set wb = xlapp.workbooks.Open("C:\Documents and Settings\youngje\Desktop\Project0020-CustomerPricingMatrix\TEMPLATE-CPMByCompany.xltm")
Set ws = wb.worksheets("1A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "1D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("1D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2A"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2A")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2B"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2B")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2C"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2C")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
strVolCat = "2D"
strSQL = "SELECT ExportTblCPMByCompany.ParentTieID, ExportTblCPMByCompany.Customer, ExportTblCPMByCompany.Volume, ExportTblCPMByCompany.GrossPerTon, ExportTblCPMByCompany.GrossSales, ExportTblCPMByCompany.GTNPerTon, ExportTblCPMByCompany.GTNSales, ExportTblCPMByCompany.PricePerTon, ExportTblCPMByCompany.NetSales, ExportTblCPMByCompany.COGSPerTon, ExportTblCPMByCompany.COGS, ExportTblCPMByCompany.MarginSales, ExportTblCPMByCompany.MarginPerTon, ExportTblCPMByCompany.MarginPct FROM ExportTblCPMByCompany Where VolumeCat = '" & strVolCat & "' AND Company = '" & strCompany & "' ORDER BY ExportTblCPMByCompany.MarginPct DESC"
Set wb = xlapp.ActiveWorkbook
Set ws = wb.worksheets("2D")
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").copyfromrecordset rs
xlapp.Visible = True
xlapp.Dialogs(xlDialogSaveAs).Show
End Select
Set rs = Nothing
Set ws = Nothing
Set wb = Nothing
Set xlapp = Nothing
End Sub
Select Case [Forms]![Frm-SelectCompanyVolCat]![Combo94]
Case "1A"
strVolCat = "1A"
Case "1B"
strVolCat = "1B"
Case "1C"
strVolCat = "1C"
Case "1D"
strVolCat = "1D"
Case "2A"
strVolCat = "2A"
Case "2B"
strVolCat = "2B"
Case "2C"
strVolCat = "2C"
Case "2D"
strVolCat = "2D"
Case Else ' Copy ALL
bCopyAll = True
End Select