我正在使用DoCmd.TransferSpreadsheet
填充表。該命令使用表單上的按鈕進行調用。傳輸完成後,我想告訴用戶添加了多少條記錄。要嘗試並完成此操作,我使用db.OpenRecordset("select * from tblImport")
然後MsgBox(rs.RecordCount)
問題是在傳輸完成之前正在調用記錄計數。無論如何要同步調用它?訪問VBA TransferSpreadsheet計數
下面是完整的代碼
Private Sub cmdVIT_Click()
On Error Resume Next
Dim strPath As String
Dim filePicker As FileDialog
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set filePicker = Application.FileDialog(msoFileDialogFilePicker)
With filePicker
.AllowMultiSelect = False
.ButtonName = "Select"
.InitialView = msoFileDialogViewList
.Title = "Select File"
With .Filters
.Clear
.Add "All Files", "*.*"
End With
.FilterIndex = 1
.Show
End With
strPath = filePicker.SelectedItems(1)
Debug.Print strPath
DoCmd.TransferSpreadsheet TransferType:=acImport, SpreadsheetType:=acSpreadsheetTypeExcel12, TableName:="tblImport", FileName:=strPath, HasFieldNames:=True
Set rs = db.OpenRecordset("select * from tblImport")
MsgBox rs.RecordCount & " records"
End Sub
它應該工作。你的代碼是什麼? – Fionnuala
我的意思是,你可以將程序代碼剪切並粘貼到你的問題中嗎? – Fionnuala
剛剛添加了代碼 – DasPete