MS Access 运行-时间错误 3162
MS Access Run-time Error 3162
我正在尝试使用此代码将文件复制到新文件夹并将文件 path/name 添加到 tblFileAttachments 中的 DocName 列。
当我 select 添加文件时,我一直收到此错误 "Run-time error 3162...You tried to assign the Null Value to a variable that is not a Variant data type."
这是我的表格
tblFileAttachments
- DocID
- DocName
- RequestID_FK
tblRequests
- RequestID
- PFName
- PLName
- PBusinessName
我有一个基于 tblFileAttachments 的表单,其中包含 DocID、DocName 和 RequestID_FK 字段。我还有一个 "Add File" 按钮,代码如下:
Private Sub btnAttachFile_Click()
Dim rsFile As DAO.Recordset
Dim strFilePath As String, strFilename As String
strFilePath = fSelectFile()
If strFilePath & "" <> "" Then
strFilename = Mid(strFilePath, InStrRev(strFilePath, "\") + 1)
With CurrentDb.OpenRecordset("tblFileAttachments")
.AddNew
!DocID = Me.DocID
!FilePath = strFilePath
!FileName = strFilename
.Update
End With
End If
End Sub
调试错误,高亮显示
!DocID = Me.DocID
DocID
可能是自动编号列?
然后在创建新记录时根本不要分配它,只需省略这一行:
!DocID = Me.DocID
ID 将自动生成。
我正在尝试使用此代码将文件复制到新文件夹并将文件 path/name 添加到 tblFileAttachments 中的 DocName 列。
当我 select 添加文件时,我一直收到此错误 "Run-time error 3162...You tried to assign the Null Value to a variable that is not a Variant data type."
这是我的表格
tblFileAttachments
- DocID
- DocName
- RequestID_FK
tblRequests
- RequestID
- PFName
- PLName
- PBusinessName
我有一个基于 tblFileAttachments 的表单,其中包含 DocID、DocName 和 RequestID_FK 字段。我还有一个 "Add File" 按钮,代码如下:
Private Sub btnAttachFile_Click()
Dim rsFile As DAO.Recordset
Dim strFilePath As String, strFilename As String
strFilePath = fSelectFile()
If strFilePath & "" <> "" Then
strFilename = Mid(strFilePath, InStrRev(strFilePath, "\") + 1)
With CurrentDb.OpenRecordset("tblFileAttachments")
.AddNew
!DocID = Me.DocID
!FilePath = strFilePath
!FileName = strFilename
.Update
End With
End If
End Sub
调试错误,高亮显示
!DocID = Me.DocID
DocID
可能是自动编号列?
然后在创建新记录时根本不要分配它,只需省略这一行:
!DocID = Me.DocID
ID 将自动生成。