Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 如何更新附件和文件路径?_Ms Access_Vba - Fatal编程技术网

Ms access 如何更新附件和文件路径?

Ms access 如何更新附件和文件路径?,ms-access,vba,Ms Access,Vba,我已经创建了一个表,在该表中保存附件(在外部文件夹中)和文件路径。当我试图用另一个附件更新现有附件时,它不起作用。请参见下面的“添加文件”代码和“更新按钮”代码 '下面是更新按钮代码 Private Sub Command88_Click() 'On Error Resume Next Dim strLokacioni As String: strLokacioni = "C:\Users\HSE\Desktop\datas\" & getFileName(Me.path.V

我已经创建了一个表,在该表中保存附件(在外部文件夹中)和文件路径。当我试图用另一个附件更新现有附件时,它不起作用。请参见下面的“添加文件”代码和“更新按钮”代码

'下面是更新按钮代码

 Private Sub Command88_Click()
 'On Error Resume Next

 Dim strLokacioni As String: strLokacioni = "C:\Users\HSE\Desktop\datas\" &   getFileName(Me.path.Value)
Me.path = strLokacioni

CurrentDb.Execute "UPDATE tbl_tracker " & _
       " SET IncNo = " & Me.txtInc & _
       ", path = '" & strLokacioni & "'" & _
       ", filename = '" & Me.filename & "'" & _
       ", PATS = '" & Me.txtPATS & "'" & _
       ", SAP = '" & Me.txtSAP & "'" & _
       ", First = '" & Me.txtFirst & "'" & _
       ", Last = '" & Me.txtLast & "'" & _
       ", IncDate = '" & Me.txtDate & "'" & _
       ", Location = '" & Me.cmbLoc & "'" & _
       ", Description = '" & Me.txtDesc & "'" & _
       ", OshaType = '" & Me.cmbOsha & "'" & _
       ", Inctype = '" & Me.cmbType & "'" & _
       ", RootCause = '" & Me.txtCause & "'" & _
       ", Inspector = '" & Me.cmbInsp & "'" & _
       ", Surfaces = '" & Me.cmbSur & "'" & _
       ", WeatherCon = '" & Me.cmbWcon & "'" & _
       ", WorkRelated = '" & Me.cmbRelated & "'" & _
       ", IncTime = '" & Me.txtTime & "'" & _
       " WHERE IncNo = " & Me.txtInc.Tag


 Dim fso As Object
 Set fso = VBA.CreateObject("Scripting.FileSystemObject")
 fso.CopyFile Me.path.Value, strLokacioni
 Set fso = Nothing


       MsgBox "Record Updated", vbInformation, "Information"
       Me.tbl_tracker_subform.Form.Requery

End sub
而Command88_单击开始时的值Me.path.value来自:

Public Function getFileName(ByVal strPath As String) As String 
    If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then 
        getFileName = getFileName(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
    End If 
End Function 
Private Sub cbdBrowse_Click() 
    On Error Resume Next 
    Dim f As Object
    Set f = Application.FileDialog(msoFileDialogFilePicker)
    f.AllowMultiSelect = False 
    f.Show 
    Me.path.Value = f.SelectedItems(1) 
End Sub
公共函数getFileName(ByVal strPath作为字符串)作为字符串
如果右$(strPath,1)“\”和Len(strPath)>0,则
getFileName=getFileName(左$(strPath,Len(strPath)-1))+Right$(strPath,1)
如果结束
端函数
私有子目录浏览\单击()
出错时继续下一步
将f作为对象
Set f=Application.FileDialog(msoFileDialogFilePicker)
f、 AllowMultiSelect=False
f、 展示
Me.path.Value=f.SelectedItems(1)
端接头

当我像您在这里一样使用更新查询时,我将始终使用以下语法

dim db as database
set db = currentDb
db.execute "UPDATE...."
您需要同样的吗?或者我已经为此走了很长一段路了


此外,我会留下评论,因为这可能不是答案。不幸的是,由于rep的原因,当我像您在这里一样使用更新查询时,我将始终使用以下语法

dim db as database
set db = currentDb
db.execute "UPDATE...."
您需要同样的吗?或者我已经为此走了很长一段路了


此外,我会留下评论,因为这可能不是答案。不幸的是,我不能,因为repWhere是Command88\u click开始时的值
Me.path.value
在哪里?Where是Command88\u click开始时的值
Me.path.value
在哪里??