2012-10-25 79 views
0

我嘗試了幾種不同的方式,但它在第一個之後不斷停止。我嘗試添加其他窗體,窗體1運行一個打開,然後窗體1打開窗體2運行一個導出等,但沒有奏效。我嘗試暫停,do while not isloaded(next form)等,但沒有奏效。無法從一個「表單加載」或「表單打開」向MS Excel 2010導出多個MS Access 2010查詢

Option Compare Database 
Private Sub Form_Load() 
On Error GoTo Err_Form_Load 

'I tried 9 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _ 
"AllActiveABC", _ 
"Y:\Projects\Protocol Folders\AllActiveABC.xls", True 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _ 
"All-ActiveABC", _ 
"Y:\Projects\Protocol Folders\AllFilteredABC.xls", True 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _ 
"All-ActiveABC", _ 
"Y:\Projects\Protocol Folders\AllFilteredABC.xls", True 

'I tried 12 and 12XML 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12xlm, _ 
"AllActiveABC", _ 
"Y:\Projects\Protocol Folders\AllActiveABC.xls", True 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12xlm, _ 
"AllFilteredABC", _ 
"Y:\Projects\Protocol Folders\AllFilteredABC.xls", True 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12xlm, _ 
"AllActiveABC", _ 
"Y:\Projects\Protocol Folders\AllActiveABC.xls", True 

'I tried it as a function 
'see function below the three exports 

Call exportData("All-FilteredABC", _ 
"Y:\Projects\Folders\All-FilteredABC.xlsx") 
Call exportData("AllActiveABC", _ 
"Y:\Projects\Folders\AllActiveABC.xlsx") 
Call exportData("AllABC", _ 
"Y:\Projects\Folders\AllABC.xlsx") 


Function exportData(queryName As String, strSaveFileName As String) 

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, queryName, strSaveFileName, True 

End Function 

沒有運氣。我對所有嘗試過的東西以及我喜歡的所有結果感到困惑,在現有的工作簿中創建了一個新的空白工作表,但最終以_1結尾,在一次導出後停止,將其全部導出。

回答

0

嘗試在每個DoCmd後輸入DoEvents命令。允許一切趕上

DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel9,_ 「AllActiveABC」,_ 「Y:\項目\文件夾協議\ AllActiveABC.xls」,真

的DoEvents