2017-07-25 122 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會自動生成。