Results 1 to 3 of 3
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365

    Find the path name from a file name

    Hi Guy's, how can I find the location (path name) from a file name that is like my input ?



    Not done any code yet but something like
    ie:

    Dim strFileName as String, strPathName as String, strInput As String, strFolderReturn as String

    StrInput = INputbox("Enter Abbreviated File Name ?")

    strFileName = "*.* & strFileName & "*.*"

    Find Folder that matches the criteria ?????

    strPathName = C:\MyFolder"

    strfolderReturn = strPathName & vbNewline

    InputBox("Enter Folder To Open ?" & vbnewline & _
    strfolderReturn = strPathName & vbNewline
    Loop

    I may be all wrong here but try to return the listing of locations that a file name matches has found ????

    Then i can open the folder

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Code:
    i = InStrRev(sFilePath, "\")     
    If i > 0 Then
      vDir = Left(sFilePath, i)
      vFile = Mid(sFilePath, i + 1)
    endif
    
    openNativeApp vDir

    paste this code into a module to open ANY file
    usage: OpenNativeApp "c:\folder\file.pdf"
    will open it in acrobat
    and
    OpenNativeApp "c:\folder"
    will open the folder

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub

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

Similar Threads

  1. Replies: 4
    Last Post: 02-16-2019, 10:23 PM
  2. "Could not find file <file path." - Error 3024
    By jmitchelldueck in forum Access
    Replies: 4
    Last Post: 07-30-2015, 02:15 PM
  3. Replies: 2
    Last Post: 01-13-2015, 07:16 AM
  4. Replies: 2
    Last Post: 05-25-2012, 07:36 AM
  5. Replies: 10
    Last Post: 03-04-2012, 12:17 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