简体   繁体   中英

Save file path on access field

I'm using access form in which I have a button to explore files and get the path. My form is created to insert data into TABLA1.

TABLA1 contains a field named sPath in which I want to SAVE the files paths.

I reviewd ms access browse for file and get file name and path several times but I don't find solution.

What I'm doing wrong? Why filePath is not saved into sPath field.

I'm using Access 2007. Thank you very much on advance and sorry for I'm limited working with VB.

Private Sub Command7_Click()

Dim f As Object

Set f = Application.FileDialog(3)

f.AllowMultiSelect = True

If f.Show Then
    For i = 1 To f.SelectedItems.Count
        sFile = Filename(f.SelectedItems(i), sPath)
        MsgBox sPath & "---" & sFile
    Next
End If

End Sub


Public Function Filename(ByVal strPath As String, sPath) As String
    sPath = Left(strPath, InStrRev(strPath, "\"))
    Filename = Mid(strPath, InStrRev(strPath, "\") + 1)
End Function

Assuming everything else is working, I think you may have to pass your second parameter, sPath, ByRef explicitly. So:

Public Function Filename(ByVal strPath As String, ByRef sPath As String) As String
    sPath = Left(strPath, InStrRev(strPath, "\"))
    Filename = Mid(strPath, InStrRev(strPath, "\") + 1)
End Function

If you pass it by value, only the value is passed and not the address, so the variable won't reflect updates. Code is assuming sPath is a string - I don't see it declared in your code, though. Look into Option Explicit if that's the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM