vba - 预期的用户定义类型,而不是项目
问题描述
关于这个错误,我已经浏览了几个关于 SF 的页面。这是我第一次尝试通过 VBA 向 Access 添加记录。这是我的代码:
Option Compare Database
Public Sub Retrieve_SOPS()
' Retrieve SOP files
'Record starting timer - BEGIN
Dim StartTime As Double
StartTime = Timer
'Set network folder path
Const FolderPath As String = "\\JACKSONVILLE-DC\Common\SOP's for JV\SOPs Final"
'Instantiate FSO
Dim oFSO As Object
Dim oFolder As Object
Dim oFiles As Object
Dim oFile As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(FolderPath)
Set oFiles = oFolder.Files
'Instantiate DAO
Dim db As DAO
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblSOP", dbOpenDynaset)
Dim v As Variant
'Loop through each file in FSO
For Each oFile In oFiles
'Remove temporary/hidden files
If (oFile.Attributes And 2) <> 2 Then
'Split filename
v = Split(oFile.Name, "-")
' Instantiate Necessary Variables
Dim file_path As String
Dim file_id As Integer
Dim file_title As String
Dim lang_code As String
Dim creation_date As String
file_path = oFile.Path
file_id = v(2)
file_title = v(4)
lang_code = v(5)
'If dimension in array exists; Remove file extension
If UBound(v) >= 6 Then
creation_date = v(6)
End If
With rs
.AddNew
.Fields("file_path").Value = file_path
.Fields("file_id").Value = file_id
.Fields("file_title").Value = file_title
.Fields("lang_code").Value = lang_code
If UBound(v) >= 6 Then
.Fields("creation_date").Value = creation_date
End If
End With
End If
'Stop For Loop (TEMP)
Exit Sub
Next oFile
End Sub
然后我得到这个错误:“编译错误:预期的用户定义类型,而不是项目”
我正在阅读 Wiley 的“Microsoft Access 2019 Bible”。
我已阅读以下链接,但仍然无法理解我做错了什么:
解决方案
你错过了更新:
With rs
.AddNew
.Fields("file_path").Value = file_path
.Fields("file_id").Value = file_id
.Fields("file_title").Value = file_title
.Fields("lang_code").Value = lang_code
If UBound(v) >= 6 Then
.Fields("creation_date").Value = creation_date
End If
.Update
End With
推荐阅读
- java - 每当我在 IntelliJ 中运行我的项目时,它都可以正常工作,但是每当我尝试将其作为 jar 运行时,它都会引发异常
- java - JMenuBar 被 JButtons 透支
- java - 项目执行时本地自动转储数据库数据
- docker - Hyperledger Fabric 第一个网络错误执行 ./byfn.sh:第 175 行:docker-compose:找不到命令
- html - CSS 剪辑路径未在打印预览中显示:为什么?
- python - 如何在 Altair 中设置语言环境?
- phpunit - Lighthouse 自动模型检测不适用于单元测试
- r - 拆分、lapply、rbind 范式。lapply 返回数字列表而不是日期索引
- reactjs - 验证反应表单的输入
- json - 从 PostgresSQL 数据库模式生成 JSON Blob 的巧妙方法