Solved

Loop thru a directory put filenames in a combobox vb6

Posted on 2014-09-13
6
143 Views
Last Modified: 2014-09-14
I have a program where a homeowner can get-track bids on different home repair-improvements
The homowner can type a new project name  into a combo box(cboBids) and new Directory is created
I want to put all the directory names in a combobox on form load
The homeowners directory is created when entered into textboxes
Typical Paths
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\Painting Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\Roofing Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\Bathroom Remodle Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\New Fence Bids
The last part
Example:
With Me.cboBids
.AddItem "paintingBids"
.AddItem "Roofing Bids"
.AddItem "Bathroom Remodle Bids"
.AddItem "New Fence Bids"
End With
How can this be done ?
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 40321025
Use either the Dir() function or the FileSystemObject.

' Add a reference to the Microsoft Scripting Runtime.
Dim fso As New FileSystemObject
Dim f As Folder
  
For Each f  In fso.GetFolder("<yourFolderPath>").SubFolders
  Debug.Print f.Name
Next f
Set fso = Nothing

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 40321113
Thanks ste5an
Is there a way without using fso ?

mstrOwnerFolder holds this:
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd
tried this to no avail:

Sub AddFoldersToCbo()
Dim MyFile, MyPath, MyName
MyPath = mstrOwnerFolder  ' Set the path.
MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
Do While MyName <> ""
      If MyPath = vbDirectory Then
        Debug.Print MyName
   End If
   MyName = Dir
Loop
End Sub

Open in new window

0
 
LVL 12

Expert Comment

by:jkaios
ID: 40322210
Try this:

Note the additions: the GetAttr() function and the last backslash in root path.

   Dim MyFile, MyPath, MyName
   MyPath = "c:\temp\"                 'Set the path (must append the last backslash "\")
   MyName = Dir(MyPath, vbDirectory)   'Retrieve the first entry.
   Do While MyName <> ""
      If (GetAttr(MyPath & MyName) And vbDirectory) Then
         If (MyName <> ".") And (MyName <> "..") Then
            Debug.Print MyName
         End If
      End If
      MyName = Dir()
   Loop

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Accepted Solution

by:
jkaios earned 500 total points
ID: 40322214
Just ensure to include double quotes to the root path as it contains spaces, if you haven't done so.
0
 

Author Closing Comment

by:isnoend2001
ID: 40322281
Thanks jkaios
0
 
LVL 12

Expert Comment

by:jkaios
ID: 40322304
My pleasure, so glad it works!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 83
Spell Check in VB6 13 137
Child Form in front 4 56
Access2016 ignore hyphen in data entry or searches 5 47
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question