china99boy
Registered User.
- Local time
- Today, 15:21
- Joined
- Apr 27, 2006
- Messages
- 161
Okay, I tried to tackle it on my own. But I think I am confusing myself. I copied the sql from my query and used that as the strSQL, but I get a compile error. I need the user to be able to select a date or between dates. How can change the vba coding to reflex this.
What I am trying to accomplish is, when the user select a date or date range and then a department it will export only that department data to the appropriate tab in the excel workbook. But if they select "All", it will export all departments. The call center department will needs to be broken down by location 801 & 3808 and position AO & CCR for each, while the other departments 004 and 007, should be divided by AO and FSO.
I added my dba and the code I currently working with in command button.
Thanks for any help provided.
What I am trying to accomplish is, when the user select a date or date range and then a department it will export only that department data to the appropriate tab in the excel workbook. But if they select "All", it will export all departments. The call center department will needs to be broken down by location 801 & 3808 and position AO & CCR for each, while the other departments 004 and 007, should be divided by AO and FSO.
I added my dba and the code I currently working with in command button.
Thanks for any help provided.
Code:
Private Sub Command36_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 strDate As String
Dim strPosition As String
Dim strDepartment As String
Dim strLocation As String
strDate = [Forms]![frmAgentSummaryExport]![txtBusinessDate]
Select Case [Forms]![frmAgentSummaryExport]![cboDepartment]
strSQL = "qryAgentSummary_Crosstab.[Agent Name], qryAgentSummary_Crosstab.Salo, (NZ(qryAgentSummary_Crosstab!GiftCard))+(NZ(qryAgentSummary_Crosstab!Other)) AS MSR, qryAgentSummary_Crosstab.Lend, qryAgentSummary_Crosstab.Mort, qryAgentSummary_Crosstab.Web FROM qryAgentSummary_Crosstab;"
Set xlapp = New Excel.Application
Set wb = xlapp.Workbooks.Open("C:\Documents and Settings\user1\Desktop/Temp.xlsx")
Case "Call Center"
strDepartment = "Call Center"
Case "004"
strDepartment = "004"
Case "007"
strDepartment = "007"
Case Else ' Export All
strDepartment = "Call Center"
strSQL = "qryAgentSummary_Crosstab.[Agent Name], qryAgentSummary_Crosstab.Salo, (NZ(qryAgentSummary_Crosstab!GiftCard))+(NZ(qryAgentSummary_Crosstab!Other)) AS MSR, qryAgentSummary_Crosstab.Lend, qryAgentSummary_Crosstab.Mort, qryAgentSummary_Crosstab.Web FROM qryAgentSummary_Crosstab;"
Set ws = wb.Worksheets(strDepartment)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").CopyFromRecordset rs
strDepartment = "004"
strSQL = "qryAgentSummary_Crosstab.[Agent Name], qryAgentSummary_Crosstab.Salo, (NZ(qryAgentSummary_Crosstab!GiftCard))+(NZ(qryAgentSummary_Crosstab!Other)) AS MSR, qryAgentSummary_Crosstab.Lend, qryAgentSummary_Crosstab.Mort, qryAgentSummary_Crosstab.Web FROM qryAgentSummary_Crosstab;"
Set ws = wb.Worksheets(strDepartment)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").CopyFromRecordset rs
strDepartment = "007"
strSQL = "qryAgentSummary_Crosstab.[Agent Name], qryAgentSummary_Crosstab.Salo, (NZ(qryAgentSummary_Crosstab!GiftCard))+(NZ(qryAgentSummary_Crosstab!Other)) AS MSR, qryAgentSummary_Crosstab.Lend, qryAgentSummary_Crosstab.Mort, qryAgentSummary_Crosstab.Web FROM qryAgentSummary_Crosstab;"
Set ws = wb.Worksheets(strDepartment)
Set rs = CurrentDb.OpenRecordset(strSQL)
ws.range("A2").CopyFromRecordset rs
GoTo ExitMySub
End Select
strSQL = strSQL & " Where VolumeCat = '" & strDepatment & "'"
Set ws = wb.Worksheets(strDepartment)
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
Attachments
Last edited: