@sergio vieira Your requirement is that the listbox display of files needs to show just the filename and not the path.
You have a field in some table that holds the path to the document, which, because it is the path, incorporates the filename.
Presumably you get the path using a filesystem dialog to pick the file you want to specify in the link to the record.
From a database design view you have two items of data: the link to the file and the filename. Your table design should reflect that difference. It will also give you the ability to edit and give the "filename" in the record a name which is meaningful to end users (or to leave as is) without altering the link to the file.
As
@Pat Hartman indicated (Post #3): "
Either create a function to extract only the file name or add a second column so you can save the values in two fields from the beginning which is the best solution."
The table structure - which in this case relates documents to specific person records, allows classification of docs to doc types and assigns a date could look like this:
Which could be maintained using a form such as
The {SELECT} button opens a file dialog to select the file. The VB for this button uses
sFile = FSBrowse("", msoFileDialogFilePicker, "All Files (*.*),*.*")
to get the path which can be assigned to strDocPath and
Me.txtDocName = GetFileName(sFile)
to default the name of the file to the Document name
The Document name can then be used to open the file on the dbl_click event (not single click - as that allows you to edit the name of the document to whatever you want.)
Call ExecuteFile(Me.txtDocLink, "Open")
Your listbox will need to present the Doc Name from the table and the event will use the open action using DocLink
The functions (placed in a VBA module) are based on Daniel Pineault's blog posts:
https://www.devhut.net/vba-extract-the-file-name-from-a-complete-file-path-and-name/
and this
https://www.devhut.net/late-binding-the-filedialog/