2014-11-06 91 views
0

使用VBA代碼請求更正和了解以下關於csv導出的查詢。使用VBA代碼請求關於csv文件導出的幫助

Private Sub VAT_OFFSET_Click() 

    strDestPtah = IIf(Right(txtDestpath.Value, 1) = "\", txtDestpath.Value, txtDestpath.Value & "\") 'Automatically add "\" at the end, if not exist 

    DoCmd.TransferText TransferType:=acExportDelim, , TableName:="VAT_OFFSET", Filename:=strDestPtah & "GRT_OUTPUT.csv", HasFieldNames:=True 

End Sub 

過網,我發現下面的查詢

DoCmd.TransferText acExportDelim, , "tmpExport", "C:\export.csv" 

所以按我的理解,「tmpexport」是從那裏數據將被導出爲CSV和而非C:\export.csv我有表名輸入用於手動輸入窗體路徑的變量(strDestPtah)。

+0

您是否收到錯誤? – weloytty 2014-11-06 13:18:24

+0

是的,它的complie erro:語法錯誤 – 2014-11-06 13:21:29

回答

0

如果您打算限定參數名稱,則不需要保留空白參數名稱。所以,你可以做

DoCmd.TransferText acExportDelim, , "VAT_OFFSET", strDestPtah & "GRT_OUTPUT.csv", True 

DoCmd.TransferText TransferType:=acExportDelim, TableName:="VAT_OFFSET", Filename:=strDestPtah & "GRT_OUTPUT.csv", HasFieldNames:=True 
+0

謝謝,真的很感謝你的幫助Weloytty。現在它顯示運行時錯誤:3615:類型在表達式中不匹配。 – 2014-11-06 13:32:39

+0

你把代碼改成了什麼?您可以在http://msdn.microsoft.com/en-us/library/office/ff835958(v=office.15).aspx – weloytty 2014-11-06 13:51:04

+0

查看參數以及它們的值應該再次感謝Weloytty ..... I沒有改變任何東西只是複製粘貼上面你分享的代碼。這個問題與生成輸出的主腳本(查詢)有關嗎? – 2014-11-07 03:45:52