2017-07-25 121 views
0

我试图用这个代码将文件复制到一个新的文件夹和文件路径/名tblFileAttachments添加到柱可采用DocName。MS Access运行时错误3162

当我选择要添加的文件,我不断收到此错误“运行时错误3162 ...你试图NULL值赋值给一个变量是不是Variant数据类型。”

下面是表我有

tblFileAttachments 
- DocID 
- DocName 
- RequestID_FK 

tblRequests 
- RequestID 
- PFName 
- PLName 
- PBusinessName 

我基于与的DocID,并且可采用DocName领域RequestID_FK一个tblFileAttachments形式。我也有下面的代码“添加文件”按钮:

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 

回答

0

DocID可能是一个自动编号列?

,同时创造了新的记录,则不会为它分配在所有的,只是离开了这一行:

!DocID = Me.DocID 

的ID会自动生成。