Re: wildacard character

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Allen,

I am not sure if this is what I need. U see I have a form created that
basically displays a staff picture from a CD.

The code that I have entered in the on current in the form properties is:

Private Sub Form_Current()


If Dir("c:\" & Me![driver_rec] & ".jpg") = "" Then

Me![ImageFrame].Picture = "c:\NoImage.jpg"
MsgBox "Picture doesn't exist for this User!!!"
Else
Me![ImageFrame].Picture = "e:\" & Me![driver_rec] & ".jpg"
End If

End Sub

so basically what i need is for the image to open when the picture is found.
except the record is located in a subfolder and I do not know the name as
they are scanned by an external company and it is different on each CD.

I would be delighted if a simple solution exists

Thanks

--
Phil


"Allen Browne" wrote:

The example below shows how to list files in a folder and subfolders:


Public Function ListFiles(strPath As String, _
Optional strFileSpec As String, _
Optional bIncludeSubfolders As Boolean)
On Error GoTo Err_Handler
'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
Dim vItem As Variant

Call FillDir(colDirList, strPath, strFileSpec, bIncludeSubfolders)

'List the items. (Or, you could add them to a list box.)
For Each vItem In colDirList
Debug.Print vItem
Next

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_Handler
End Function

Private 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

'Add the files to the folder.
strFolder = TrailingSlash(strFolder)
strTemp = Dir(strFolder & strFileSpec)
Do While strTemp <> vbNullString
colDirList.Add strFolder & strTemp
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)
Next vFolderName
End If
End Function

Private 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

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Phil" <Phil@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CC5BD465-EACF-429B-818B-F4C6569617F4@xxxxxxxxxxxxxxxx
Hello again,

What could I use to perform the following.

I have a CD with data on it except its not all in one directory

eg:

E:\Pictures\021\
E:\Pictures\022\
E:\Pictures\023\
E:\Pictures\054\

The problem is that I have many CD's with at pictures with various sub
directories.
Is there a wildcard character that I could use to substitite for the
folder
name?

Thanks
--
Phil



.



Relevant Pages

  • Re: Variable that is automatically 0
    ... Dim cartella, Categoria As Variant ... Dim, MyPath As String ... in the strFileSpec argument. ... Dim strTemp As String ...
    (microsoft.public.access.formscoding)
  • Re: Variable that is automatically 0
    ... Dim cartella, Categoria As Variant ... Dim, MyPath As String ... in the strFileSpec argument. ... Dim strTemp As String ...
    (microsoft.public.access.formscoding)
  • Re: Variable that is automatically 0
    ... Originally I thought the variant variable would be initialized to Null and I could use Nz to change it to 0. ... Only one file name includes that string with a space before and after it. ... Dim colDirList As New Collection ... Dim strTemp As String ...
    (microsoft.public.access.formscoding)
  • RE: adding text to time
    ... Dim strNum As String ... Dim strFrac As String ... Dim strTemp As String ... Dim iCtr As Integer ...
    (microsoft.public.access.externaldata)
  • Re: Export Data in Access Table to Mulitple Excel Files
    ... Dim qdf As DAO.QueryDef ... Dim strSQL As String, strTemp As String, strMgr As String ... Set qdf = dbs.CreateQueryDef ...
    (microsoft.public.access.externaldata)