Hi guys,
I am using a button to export form results to excel. The results showed are not all the fields in the table. For this example I want to export only the field [Operator TL] from the table "Data", including some criteria named "StrCriteria". When I click the button I does export to Excel, but it export all the fields in the table, no matter if I only requested [Operator TL]. Do you have any idea why is this happening? Below you may find the code VBA code:
Private Sub Command357_Click()
Dim strSQL As String
Dim strQry As String
Dim strFields As String
Dim strCriteria As String
strFields = "([Operator TL])"
strCriteria = "([Is Feedback required] = TRUE and [Site] = '" & Me.Center & "' and [Error_Accountability] = '" & Me.ErrorCombo & "' and [SDL] = '" & Me.SDLCombo & "' and [Product] = '" & Me.ProductCombo & "' and [Mispost Date] >= #" & Me.Initial & "# and [Mispost Date] <= #" & Me.Final & "#)"
strSQL = "Select (" & strFields & ") from Data where (" & strCriteria & ") order by [Mispost Date]"
strQry = "TempQueryName"
Set Db = CurrentDb
Set Qdf = Db.CreateQueryDef(strQry, strSQL)
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, _
strQry, "C:\Users\jmorasos\Documents\Test1.xls", True
DoCmd.DeleteObject acQuery, strQry
End Sub
Best regards!