I am creating a database where users can click a command button, they will be taken to a folder that is stored in a trusted location and they can choose a word document from there and all the names of chosen files will show in a list box on a form. We have the code to double click the file name to open the document. What we a开发者_开发技巧re looking for is code to show only the file name in the list box without the path.
We have used the sample code given in the question "How to show open file dialogue in access 2007 vba" from this site to set this up so far.
Any help would be great.
Execute the following code for each file name to be inserted into the list box.
Dim Chunks() As String, DocumentName As String
Chunks() = Split("\\server\share\folder\subfolder\docuemnt.doc", "\")
DocumentName = Chunks(UBound(Chunks()))
You can use the FileSystemObject to quickly get the filename part
EDIT - good suggestion from BitAccesser
Requires a reference to Microsoft Scripting Runtime, or you need to use the CreateObject("Scripting.FileSystemObject")
Const WORD_TEST_PATH As String = "C:\users\admin\test\test.doc"
Dim fso As New FileSystemObject
Dim strWordFileName As String
strWordFileName = fso.GetFileName(WORD_TEST_PATH)
Debug.Print strWordFileName
Output is: test.doc
Just replace WORD_TEST_PATH with the filename returned from your Dialog path
精彩评论