Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    172

    wildcard charcters


    strFullFileName = strSitePlanLoc & strPropertyName & ".*"
    I have the above line in a sub. It does NOT locate any file extension. I can replace the asterisk with pdf or jpg, it will find the file. But I need one statement to locate a file with any extension. Your help is appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Are you using Like instead of =?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Join Date
    Apr 2017
    Posts
    1,673
    Code:
    Left(strFullFileName,Len(strSitePlanLoc & strPropertyName)) = strSitePlanLoc & strPropertyName

  4. #4
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    172
    No. [strFullFileName = strSitePlanLoc & strPropertyName & ".*"] is all I use (without the brackets).

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    That just sets the value of a variable. How is it used?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    172
    Ok, I see what you mean now. The following is the rest.
    ' check for and add the site plan if it exist
    If strPropertyName > "" Then ' contains a value
    strFullFileName = strSitePlanLoc & strPropertyName & ".pdf"
    ' Debug.Print "strFullFileName " & strFullFileName
    ' determine if a site plan exist
    strFileName = dir(strFullFileName) ' returns only file name
    If strFileName > "" Then ' it will be 0 is no file exist
    olMailItem.Attachments.Add strFullFileName
    End If
    End If

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,824
    How are the variables populated and what values do they hold?

    If strSitePlanLoc is a folder path and strPropertyName is a filename, might need a \ between them.

    If Dir(strSitePlanLoc & "\" & strPropertyName & ".*") <> "" Then

    Works for me.
    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.

  8. #8
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    172
    If I use "jpg" on the end instead of the "*", as below:
    strFullFileName = strSitePlanLoc & strPropertyName & ".jpg"
    Then I get the correct file and directory as below:
    strFullFileName = L:\aaTS\AAFilesToCopy\Site Plans PDF\Standford Corporate Centre.jpg

    That is correct and the procedure runs correctly. However, I have different file types. I need to select any of the files. So I used the wildcard character "*" which should select every file type.

    So the one line that creates the path and file name is as follows:
    strFullFileName = strSitePlanLoc & strPropertyName & ".*"
    This produces the following variable which ends with an *
    strFullFileName = L:\aaTS\AAFilesToCopy\Site Plans PDF\Standford Corporate Centre.*
    Then I get an error which states "File name or directory name is not valid".



    strFullFileName = strSitePlanLoc & strPropertyName & ".jpg"

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,824
    The following returns empty string:

    Dir("C:\Program Files\Microsoft Office\*.*")

    The following returns a file name:

    Dir("C:\Program Files\Microsoft Office\Office14\*.*")

    The following returns the same as previous:

    Dir("C:\Program Files\Microsoft Office\Office14\AUTHZAX.*")

    Concatenation also works:

    Dir("C:\Program Files\Microsoft Office\Office14\AUTHZAX" & ".*")

    Also works if I set a variable to path string.

    x = "C:\Program Files\Microsoft Office\Office14\"

    Dir(x & "*.*")

    So the issue is not the wildcard nor its concatenation.
    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.

  10. #10
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    172
    Ok, I can't determine why it works great using the actual file extension as jpg or pdf but will not work if I use the wildcard character *.
    The only change I make is to the file extension.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,824
    Provide procedure code. Seems I've seen this question somewhere else.
    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.

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Maybe you should post the entire procedure code exactly as written, ensuring that we have the results of variables because, first, this has no quotes so it should error out anyway
    Code:
    strFullFileName = L:\aaTS\AAFilesToCopy\Site Plans PDF\Standford Corporate Centre.*
    and because I can also confirm that it's possible to use the * wildcard
    Code:
    Sub TestWildcardForExtension()
    Dim strPath As String, strFileNames As String
    Dim FoundFiles As String
    
    strPath = "C:\Users\Micron\Documents\forum1"
    FoundFiles = Dir(strPath & ".*")
    If FoundFiles = "" Then
        MsgBox "not found"
    End If
    End Sub
    but Dir will only return the 1st file that satisfies the function, thus it seems arbitrary to email whichever one it finds first. Perhaps you are ok with that.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    172
    Yes, but there is only one file with the given name. It is the file extension that varies. In other words, when we do a proposal and we have a site plan for the property, we save the site plan with that property name. The problem is that the site plans are in different formats, some are pdf, some jpg, and several other formats. So we search by the property name several times using different file extensions. It would be nice to search once using the property name and a wildcard charcter.

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Makes sense. So 2 of us said we can get it to work and suggested you post the entire procedure. Will that be coming or are you testing out my or June7's code?

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,824
    Micron, that line without quotes wasn't the code, it was just narrative to show what the variable is set with as a result of the code.

    Still have to grab each file by its full name, including the appropriate extension, in order to do something with it.

    Post your code.

    Review: http://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.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Macro using wildcard/LIKE
    By ScottySchultz in forum Macros
    Replies: 2
    Last Post: 01-26-2018, 12:54 PM
  2. Wildcard Table
    By genedi in forum Access
    Replies: 4
    Last Post: 11-19-2015, 02:14 PM
  3. Wildcard seacrh
    By andyt_2005 in forum Forms
    Replies: 4
    Last Post: 08-02-2014, 02:30 PM
  4. Using a wildcard if an IIF statement.
    By atlee in forum Programming
    Replies: 6
    Last Post: 02-23-2014, 04:02 PM
  5. Replies: 9
    Last Post: 12-05-2013, 11:48 AM

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