Results 1 to 8 of 8
  1. #1
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368

    Wildcard in directory Dir function

    Hi guys,



    My code underneath works like a charm except when i put the wildcard after the notifications directory.
    At the place of the wildcard is a directory wich holds the current year.
    Ive tryed many different things like *.* and & " * " &. But every time im getting an ivalid use of null or type mismatch error. The year directory is the current year but its just four digits as well, so im guessing
    i dont have to dimension anything as numbers.

    Anyways, any ideas on this ?

    Code:
    If Len(Dir("I:\Sec\Notifications\*\Parking report * '" & Me.Pnumber & "'.pdf")) = 0 Then   
    Me.chkmLetter = False
    Else
    Me.chkmLetter = True
    End If

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I usually iterate the directory and loop through the iteration. Never tried using a wildcard in a path. Anything between quotes should be literal text.

  3. #3
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Sorry for the late reply but im not sure what you mean by looping through the directory.
    That is, i know what iteration means but how this works im not sure.

    Can you perhaps give me an example ?

    Thanks

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I don't think you can use a wildcard character in that context. I tried something similar with DIR in the command prompt window, and it didn't work there, either.

  5. #5
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Hi John and thanks for the reply.

    I can use a wildcard in the filename (see my code).
    That makes me think a wildcard in a DIR must be possible. However if you can't make it work then i certainly can't

    Do you have any suggestions on how to solve this ?
    Every year a new directory is made. And i want the file to be checked in all directory's.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    No wildcard in path, only in file name.

    See if this helps http://www.allenbrowne.com/ser-59.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I have some examples iof iteration and looping. Basically, iterate to understand what is in the folder. Then, with your list, loop through.

    I think I have a sample that does both simultaneously. That will probably suit your need. I will post up when I get back to my desk later this evening.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    This isn't exactly the code I was looking for. But, it shows how to use the FilesystemObject Library to instantiate file and folder objects. With that, you can get the members of objects within a directory. You will have to use early binding and make a reference.

    Code:
    'Delete the PDF files in the temp folder
    Dim strFile As String
        strFile = \\Server\Folder\Temp
    Dim fsoFile As New FileSystemObject
    Dim objFolder As Folder
    Dim objFile As File
        Set objFolder = fsoFile.GetFolder(strFile)
        
            For Each objFile In objFolder.Files
            
                If InStr(objFile.Name, ".PDF") Then
                    objFile.Delete True
                End If
            
            Next
        
        Set objFolder = Nothing
    'end 'Delete the PDF files in the temp folder
    Edit: Looking at the code here, I use the word file to describe things that are actually folders. A little confusing, sorry.
    Last edited by ItsMe; 04-30-2015 at 08:14 PM. Reason: Add some info

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using a wildcard with the replace function
    By razkowski in forum Queries
    Replies: 6
    Last Post: 08-12-2014, 08:13 AM
  2. Replies: 9
    Last Post: 12-05-2013, 11:48 AM
  3. Replies: 6
    Last Post: 10-26-2012, 12:53 PM
  4. Querying a wildcard
    By undee69 in forum Queries
    Replies: 1
    Last Post: 10-15-2012, 06:00 AM
  5. Replies: 6
    Last Post: 06-15-2011, 04:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums