Private Sub btn_Click()
Dim xlFile As String, qd as dao.querydef
Dim dtable As String
dtable = "SELECT Table1.Barcode, Table1.Reject FROM Table1"
set qd=currentdb.createquerydef("myQuery",dtable)
xlFile = "rejectstatus" & Date
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"myquery", "c:\rejectstatus\" & xlFile & ".xls", True
'delete the created query
docmd.deleteObject acQuery,"myQuery"
End Sub