gpt4 book ai didi

ms-access - Access VBA TransferSpreadsheet 计数

转载 作者:行者123 更新时间:2023-12-03 04:21:25 29 4
gpt4 key购买 nike

我正在使用DoCmd.TransferSpreadsheet填充表。使用表单上的按钮调用此命令。传输完成后我想告诉用户添加了多少条记录。为了尝试实现这一点,我使用 db.OpenRecordset("select * from tblImport")然后MsgBox(rs.RecordCount)
问题是在传输完成之前调用记录计数。无论如何可以同步调用它吗?

这是完整的代码

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

最佳答案

您需要额外的一行:

Set rs = db.OpenRecordset("select * from tblImport")
'Populate recordset
rs.MoveLast
MsgBox rs.RecordCount & " records"

关于ms-access - Access VBA TransferSpreadsheet 计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14141083/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com