1
我正在編寫一個基於用戶輸入的過濾查詢的腳本,然後這個查詢中的數據將用於製作一個新表qryMyExportedData
。從那裏,數據將被輸出到ExportedData.xlsx
。當我嘗試運行我的代碼,我得到以下錯誤:運行時錯誤'2498' - Access 2010 VBA - DoCmd.Trasnferspreadsheet
Run-time error '2498': An expression you entered is the wrong data type for one of the arguments.
我的代碼:
Private Sub Query_Click()
Dim strExport as String
strExport = "SELECT * FROM qryCostDepLosses WHERE [Maintenance Type] = '" & Me.MainType & "' AND [Date] = #" & Me.Date & "#"
Set qdfNew = CurrentDb.CreateQueryDef("myExportQueryDef", strExport)
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "myExportQueryDef", CurrentProject.Path & "\ExportedData.xlsx", "True"
CurrentDb.QueryDefs.Delete qdfNew.Name 'cleanup
End Sub
我有誤差縮小到DoCmd.TransferSpreadsheet
線。我相信,strExport看起來應該是它應該的。數據也被導出到myExportQueryDef。
Jeez .. Idk我沒有注意到,謝謝你! –
沒問題,很高興我能夠幫助。我使用了這個鏈接:https://msdn.microsoft.com/en-us/library/office/ff844793.aspx,並通過參數查看了什麼不匹配。 – Newd