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

    Populate A Combo Box using string length

    Hi Guy's i have had a quick search on the web but can't find a method of this one that I would guess is quite simple.



    I am populating a combo box full of file names but what i want to try is to only add a list where another combo box is selected with the first letter such as:

    Selection combo

    Adam
    Andrew
    Brian
    Bob
    Charlie
    Chris
    Colin
    David
    Dennis
    Daniel

    etc....

    My code will list all files where these file names are located, where would i add a string when if i select Bob for example, the file names populated only shows files that start with the letter B ?

    I know it would likely be Len Function but how do I add to oFile Name ?

    cboImages are populated from after update of a combo listing form a table called cboSelect

    So i'm guessing it is using Len(cboSelect,1) but its how and where do i add in the code below ?


    Code:
    Dim oFSO As ObjectDim oFolder As Object
    Dim oFile As Object
    Dim i As Integer
    
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    
    
    Set oFolder = oFSO.GetFolder("T:\Server\Enquiry Pics\")
    
    
    
    
    For Each oFile In oFolder.Files
    
    
        Me.cboImages.AddItem oFile.Name
    
    
        i = i + 1
    
    
    Next oFile

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    would have thought something like

    if left(oFile.Name,1)=left(cboNames,1) then Me.cboImages.AddItem oFile.Name

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Ahh OK, thank you CJ London, will test that line with your suggestion

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Thank you CJ London, somthing so simple works, why do we look at how to do things the hard way when that simple line was the answer

    Kindest Regards

    Code:
    Dim oFSO As ObjectDim oFolder As Object
    Dim oFile As Object
    Dim i As Integer
    
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    
    
    Set oFolder = oFSO.GetFolder("T:\Server\Enquiry Pics\")
    
    
    
    
    For Each oFile In oFolder.Files
    
    if left(oFile.Name,1)=left(cboNames,1) then 
    
              Me.cboImages.AddItem oFile.Name
        
    
        i = i + 1
    
    End If
    
    Next oFile

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

Similar Threads

  1. filtering string length
    By fishhead in forum Programming
    Replies: 1
    Last Post: 08-27-2020, 08:12 AM
  2. Replies: 3
    Last Post: 07-20-2020, 01:04 PM
  3. cannot be a zero-length string
    By MadTom in forum Forms
    Replies: 5
    Last Post: 03-09-2020, 07:52 AM
  4. Field Cannot Be A Zero Length String Error
    By VSCurtis in forum Programming
    Replies: 6
    Last Post: 05-09-2017, 10:52 PM
  5. Replies: 6
    Last Post: 01-21-2014, 06:39 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