Results 1 to 11 of 11
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find folder name (2003 SP3)

    Hello All,
    I have some code that is looking to see if a folder exists on a network drive. It works as long as the folder name matches exactly the string I am looking for. I would like to have it find anything starting with the value that I am searching for. For instance, the folder could be named "123456" or "123456 Customer Name". The code:

    strHLAddress = "usabox12ServiceDataCustomer filesSystem Data" & Me.Sales_order & ""

    is looking for the sales order folder but I would like to use a wildcard, similar to dos commands, like "*", after the sales order number. Is this something I can do?

    Thanks,
    Mark

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find folder name (2003 SP3)

    You can test like this:
    <code>
    strHLAddress = "usabox12ServiceDataCustomer filesSystem Data" & Me.Sales_order & "*"
    If Dir(strHLAddress, vbDirectory) = "" Then
    ' There is no such folder
    Else
    ' There is at least one such folder
    End If</code>

  3. #3
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find folder name (2003 SP3)

    Hi Hans,
    What I am trying to do is open the folder location after it figures out if the folder is there. Unfortunately, the name of the folder may be different than what is located in the form control. The folder name will always begin with 6 numbers (i.e. 123456) but there may be something that comes after it, like a customer name. I want to search for the folder that starts with the 6 numbers and open that folder. Now, how can I do that?

    Thanks,
    Mark

  4. #4
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find folder name (2003 SP3)

    Edited by HansV to provide link to post - see <!help=19>Help 19<!/help>

    I have looked through <post:=715155>post 715155</post:> and this is the type pf path I am looking for.

    Similar issue I have but the text following the initial string will be different. Is there a way to step through a main folder(fixed location) looking for a specific subfolder starting with a known string? I am not looking to store that info in any way, just to open the folder it finds. The code I have now looks for the folder name and when it doesn't find it exactly, it opens the main folder for browsing.

    Thanks,
    Mark

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find folder name (2003 SP3)

    The expression Dir(strHLAddress, vbDirectory) from my previous reply will return the name of the first folder that matches the pattern, or an empty string if there is no matching folder.

  6. #6
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find folder name (2003 SP3)

    Hi Hans,
    I tried as you stated before with the "*" after the first 6 numbers and it doesn't return that folder name. The DIR command is not coming back with anything but the folder is there. Got any other ideas?

    Thanks,
    Mark

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find folder name (2003 SP3)

    Check carefully whether there's a typo somewhere. The code does work, I've tested it (again).

  8. #8
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find folder name (2003 SP3)

    Hi Hans,
    Here is what I have:

    If IsNull(Sales_order) Or Sales_order = "" Then
    strHLAddress = "usabox12ServiceDataCustomer filesSystem Data"
    Else: strHLAddress = "usabox12ServiceDataCustomer filesSystem Data" & Me.Sales_order & "*"
    End If

    strHLAddress1 = strHLAddress

    If Dir(strHLAddress1, vbDirectory) = "" Then
    MsgBox "Sales Order folder not found. Please find the correct folder and update name.", vbOKOnly
    strHLAddress = "usabox12ServiceDataCustomer filesSystem Data"
    End If

    Me.Command32.HyperlinkAddress = strHLAddress

    In this case, the folder name is "usabox12ServiceDataCustomer filesSystem Data250076, customer name". The code is looking for 250076* and the dir command doesn't find it.

    How are you testing it? If I create a folder with the 6 numbers alone, it opens it every time without fail.

    Thanks,
    Mark

  9. #9
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find folder name (2003 SP3)

    Hi again Hans,
    Testing some more shows that the DIR command is returning something. However, the hyperlink command or shell results in the following error (see attachment)

    Thanks,
    Mark
    Attached Images Attached Images

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find folder name (2003 SP3)

    Perhaps Sales_order doesn't equal 250076?

    I created a subfolder named 123456, Jones in a folder named Cata.
    I used the following test procedure:

    Sub Test()
    Dim strParent As String
    Dim strName As String
    Dim strFolder As String
    strParent = "Cata"
    strName = "123456"
    strFolder = Dir(strParent & "" & strName & "*", vbDirectory)
    If strFolder = "" Then
    MsgBox "Not found", vbExclamation, "Folder Test"
    Else
    MsgBox strFolder, vbInformation, "Folder Test"
    End If
    End Sub

    Result is shown below.
    Attached Images Attached Images
    • File Type: png x.png (5.7 KB, 0 views)

  11. #11
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find folder name (2003 SP3)

    Hi Hans,
    OK, it is working now. What I think happened was that the string was being changed back to the value with the * in it and therefore couldn't open the directory. Now I am using this and it works as advertised:


    Private Sub Command32_Click()
    On Error Resume Next

    Dim strParent As String
    Dim strName As String
    Dim strFolder As String, strFolder1 As String
    strParent = "usabox12ServiceDataCustomer filesSystem Data"
    strName = Me.Sales_order
    strFolder = Dir(strParent & "" & strName & "*", vbDirectory)
    If strFolder = "" Then
    MsgBox "SO folder not found", vbExclamation, "Folder Test"
    Else
    'MsgBox strFolder, vbInformation, "Folder Test"
    strFolder1 = strParent & strFolder
    End If

    Shell (strFolder1), vbNormalFocus
    'Me.Command32.HyperlinkAddress = strFolder1

    End Sub

    Thanks for the help!
    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •