MS Access VBA出口表格结果,以在哪里条件优秀

我有一个有很多字段的表格,然后是一个仅占用这些字段的表格。 我在表格上有一个searchbutton,您可以select某些logging。 有没有在VBA的方式从窗体中导出结果,但包括表中的所有字段。

这是我从我发现的一些代码的尝试:

Private Sub Command49_Click() Dim strWhere As String Dim strFile As String Const strcStub = "SELECT * FROM tblMaster " & vbCrLf Const strcTail = "ORDER BY ID;" Const strcExportQuery = "Query1" 'Name of the query for exports. 'Keyword If Nz(Me.tKW, "") <> "" Then strWhere = strWhere & "[iavmtitle] Like '*" & Replace(Me.tKW, " '", "''") & "*' AND " End If 'Release Date From If Nz(Me.tRF, "") <> "" Then strWhere = strWhere & "[releaseDate] between " & "#" & Me.tRF & "# AND #" & Me.tRT & "#" & " AND " End If 'Expliots If Nz(Me.cmbExploits, "") <> "" Then strWhere = strWhere & "[knownExploits] = '" & Me.cmbExploits & "' AND " End If 'Incidents If Nz(Me.cmdIncidents, "") <> "" Then strWhere = strWhere & "[knownDodIncidents] = '" & Me.cmdIncidents & "' AND " End If 'Release Date From If Nz(Me.txtSaveSend, "") <> "" Then strWhere = strWhere & "[lastSaved] > " & "#" & Me.txtSaveSend & "#" & " AND " End If If strWhere <> "" Then strWhere = Left(strWhere, Len(strWhere) - 5) 'Remove the extra AND Me.Filter = strWhere Me.FilterOn = True Else Me.Filter = "" Me.FilterOn = False End If If Me.FilterOn Then strWhere = "WHERE " & Me.Filter & vbCrLf End If CurrentDb.QueryDefs(strcExportQuery).SQL = strcStub & strWhere & strcTail strFile = "C:\Data\MyExport.xls" DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _ strcExportQuery, strFile End Sub