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

    Displaying Folder Names Inputbox

    Hi Guy's how can i display folder names from the below code please ?



    So inputbox is something like

    InputBox("Select Folder From Directory " & Me.cboCustomerSource & vbnewline & vbnewline & _
    Chr(149) "1 " & Chr(149) = & " Folder Name 1" & vbNewLine & _
    Chr(149) "2 " & Chr(149) = & " Folder Name 2" & vbNewLine & _
    Chr(149) "3 " & Chr(149) = & " Folder Name 3" & vbNewLine & _
    Chr(149) "4 " & Chr(149) = & " Folder Name 4","SELECT FOLDE")

    Code:
    If Me.cboCustomerSource <> "" ThenIf Me.cboCustomer = Me.cboCustomerSource Then
    Dim SrcPath As String, srcFile As String, strFld As String, myFld As String
    SrcPath = "T:\" & Me.cboCustomerSource & "\" ' THERE MAY 4 folders in SrcPath
    myFld = InputBox("Enter The Folder To Populate ?" & vbNewLine & vbNewLine & _
    SHOW FOLDER NAMES HERE, "ENTER FOLDER NAME")
    srcFile = myFld & "\" & Me.cboViewPO ' MyFld Would be come the result of input box Number selected
    Application.FollowHyperlink SrcPath & srcFile
    End If
    End If
    If We Add a Folder within the SrcPath so there is now 5 folders in there and not 4, can the input box now list 5 ?????

  2. #2
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Use a list box, populate that with the folder names and run your code from the list box selection.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    I agree with minty but thought I'd give it a shot.

    try this
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    heyyy thank you guy's will give it a go

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    BTW, I copied and pasted some of the code for the example but made changes to it.
    Even though one procedure is named RecursiveSearchFolders it is not recursive. I was too lazy to change its name.
    It didn't appear you were concerned with subfolders.
    I also didn't add error handling for instance if they enter a 7 and there are only 6 folders.

    edit: Now that I'm looking at it again I see a few changes that can be made and still accomplish the same thing thing with a little less code.

    heres the changes:

    Code:
    Option Compare Database
    Option Explicit
    
    
    Dim dict As New Scripting.Dictionary
    
    
    Private Sub Command2_Click()
    
    
        Me.Text0 = FSBrowse(, msoFileDialogFolderPicker)    'get the top folder
    
    
    End Sub
    
    
    Private Sub Command3_Click()
    
    
        Dim strMsg As String
        Dim x As Variant
    
    
        If Nz(Me.Text0, "") = "" Then Exit Sub
    
    
        Call RecursiveSearchFolders(Me.Text0, strMsg) 'populate the dictionary and get the strMsg (strMsg passed ByRef)
    
    
        x = InputBox(strMsg, "Select a Folder Number")
        
        If x > dict.Count Then Exit Sub  'if number entered is higher than folder count exit sub
    
    
        If Nz(x, "") <> "" Then
        
            Application.FollowHyperlink dict.Item(x)
            
        End If
    
    
    End Sub
    
    
    Sub RecursiveSearchFolders(fld As String, ByRef strMsg As String)
    
    
        dict.RemoveAll  'clear dictionary
    
    
        Dim fold As Folder
        Dim fldr As Folder
        Dim i As Integer
    
    
        i = 1
    
    
        Dim fso As New FileSystemObject
    
    
        Set fldr = fso.GetFolder(fld)
    
    
        For Each fold In fldr.SubFolders
    
    
            dict.Add CStr(i), CStr(fold.Path)   'add number (i) as index and Folder path as item to dictionary
            
            strMsg = strMsg & i & Chr(9) & fold.Name & vbNewLine 'add number and folder name to strMsg
    
    
            i = i + 1
    
    
        Next
    
    
    End Sub
    Also note you need a reference to MS scripting runtime and MS office XX object library.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 5
    Last Post: 10-26-2019, 04:51 PM
  2. Create Folder based on field names
    By dinsey90 in forum Access
    Replies: 12
    Last Post: 10-04-2017, 03:38 PM
  3. combobox based on folder names
    By sdel_nevo in forum Programming
    Replies: 3
    Last Post: 11-18-2014, 12:40 PM
  4. count number of file names within a folder containing
    By dumbledown in forum Programming
    Replies: 2
    Last Post: 04-24-2012, 02:55 AM
  5. Displaying images from another folder
    By w3leon in forum Access
    Replies: 0
    Last Post: 01-30-2009, 06:18 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