Exporting specific fields from from results using SQL query is showing all fields. (1 Viewer)

jmorasos

New member
Local time
Today, 08:34
Joined
Jul 3, 2018
Messages
1
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!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:34
Joined
Aug 30, 2003
Messages
36,118
As answered elsewhere:

You can use this to check the SQL:

http://www.baldyweb.com/ImmediateWindow.htm

personally I would get rid of all the parentheses around the field, though I don't know that it causes this problem. I'd also comment out the line deleting the query and see if it contains the expected SQL.
 

Users who are viewing this thread

Top Bottom