> Hi,
> I tried to use what you wrote but without success.
> But I need something similar.
>
> How I can add some valueto show files in listbox or some textbox?
> E.g. I have field [Number] with numbers. And this number (e.g. 0022038) is
> including in a file name.
> E.g. file names: 0022038.doc; COR-1LD-1871-1226-0022038.doc; COR-1LD-1871-
> 1226-0022038.pdf; COR1LD-1871-1226-0022038.doc.
> How I can restrict a list only to files contain a value from form field
> [Number]?
> How I can list only file names without full path?
> I tried this but it’s not working:
> Call ListFiles(MyPath, "*" & Format(Me!Number, "0000000") & "*.doc", Me.
> lstFileList)
>
> Where
>
> Dim cartella, Categoria As Variant
> Dim, MyPath As String
>
> cartella = Application.CurrentProject.Path
> Categoria = Me!Categoria
> MyPath = cartella & "\AD\DOC\" & Categoria & "\"
>
> Thanks for your help.
>
>
> BruceM wrote:
>>Thanks for the reply, and thanks to Tom too. I will respond in this
>>section
>>of the thread.
>>
>>Originally I thought the variant variable would be initialized to Null and
>>I
>>could use Nz to change it to 0. However, it shows up as Empty when I set
>>a
>>watch on it. VBA Help seems to confirm this.
>>
>>I can't explicitly assign a value to the variable because it resets each
>>time through the code. I will use an integer instead. Here is the code
>>from which I adpated mine:
>>
>>
http://allenbrowne.com/ser-59.html>>
>>The difference is that I exit the procedure as soon as the array contains
>>a
>>value. It seemed clumsy to build an array that is limited to a single
>>element or value, but I could not find an alternative. Twice I posted on
>>that topic, but did not receive any replies, so since my clumsy system
>>works
>>I abandoned for now the attempt to find something better. Since we're on
>>the subject I have posted my code below, minus error handling and with a
>>simplifed message box.
>>
>>As I mentioned, I am using the code to find a particular file by using the
>>strFileSpec argument. The main form's record contains a value such as
>>08-22. Only one file name includes that string with a space before and
>>after it. The file naming convention is such that I can reliably specify
>>[FieldName] in the strFileSpec argument.
>>
>>Public Function ListFiles(strPath As String, Optional strFileSpec As
>>String,
>>_
>> Optional bIncludeSubfolders As Boolean)
>>
>>' Purpose: List the files in the path.
>>' Arguments: strPath = the path to search.
>>' strFileSpec = "*.*" unless you specify differently.
>>' bIncludeSubfolders: If True, returns results from
>>subdirectories of strPath as well.
>>' Method: FilDir() adds items to a collection, calling itself
>>recursively
>>for subfolders.
>>
>> Dim colDirList As New Collection
>>
>> Call FillDir(colDirList, strPath, strFileSpec, bIncludeSubfolders)
>>
>>End Function
>>
>>Public Function FillDir(colDirList As Collection, ByVal strFolder As
>>String,
>>strFileSpec As String, _
>> bIncludeSubfolders As Boolean)
>>
>> 'Build up a list of files, and then add add to this list any additional
>>folders
>> Dim strTemp As String
>> Dim colFolders As New Collection
>> Dim vFolderName As Variant
>> Dim lngCol As Long
>> Dim intCount As Integer
>>
>> 'Add the files to the list
>> strTemp = Dir(strFolder & strFileSpec)
>> Do While strTemp <> vbNullString
>> colDirList.Add strFolder & strTemp
>> If colDirList.Count > 0 Then
>> Application.FollowHyperlink (strFolder & strTemp)
>> Exit Function
>> End If
>> strTemp = Dir
>> Loop
>>
>> If bIncludeSubfolders Then
>> 'Build collection of additional subfolders.
>> strTemp = Dir(strFolder, vbDirectory)
>> Do While strTemp <> vbNullString
>> If (strTemp <> ".") And (strTemp <> "..") Then
>> If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0& Then
>> colFolders.Add strTemp
>> End If
>> End If
>> strTemp = Dir
>> Loop
>>
>> 'Call function recursively for each subfolder.
>> For Each vFolderName In colFolders
>> Call FillDir(colDirList, strFolder & TrailingSlash(vFolderName),
>>strFileSpec, True)
>> lngCol = colFolders.Count
>> If intCount = 0 Then
>> intCount = 1
>> Else
>> intCount = intCount + 1
>> End If
>> If intCount = lngCol And _
>> colDirList.Count = 0 Then
>> MsgBox "File not found"
>> End If
>> Next vFolderName
>> End If
>>
>>End Function
>>
>>Public Function TrailingSlash(varIn As Variant) As String
>>
>> If Len(varIn) > 0& Then
>> If Right(varIn, 1&) = "\" Then
>> TrailingSlash = varIn
>> Else
>> TrailingSlash = varIn & "\"
>> End If
>> End If
>>
>>End Function
>>
>>I call the code from a command button thus:
>>
>> Dim colDirList As New Collection
>> Dim strPath As String, strFile As String
>>
>> strPath = "\\ServerName\ShareName\FolderName\"
>> strFile = "* " & Me.FieldName & " *.doc"
>>
>> Call FillDir(colDirList, strPath, strFile, True)
>>
>>> While I prefer explicitly setting the value, any numeric variable (Byte,
>>> Integer, Long, Single, Double, Decimal and even Currency) will be
>>[quoted text clipped - 34 lines]
>>>>
>>>> which also seems to start at 0.
>