View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tyrell Tyrell is offline
external usenet poster
 
Posts: 8
Default Populating Combo Boxes

I am trying to populate combo boxes using the code below but it is not
working for me. Once the workbook is opened I want the first combo box to
populate automatically. From what is selected by the user from the first
combo box I want the second to populate and so on until the Excel file is
selected in the fourth combo box. What am I doing wrong? Any help on this
would be greatly appreciated!


'Populate Combo Boxes
Dim FSO As Object
Dim FSO1 As Object
Dim FSO2 As Object
Dim FSO3 As Object
Dim sFolder As String
Dim s1Folder As String
Dim s2Folder As String
Dim s3Folder As String
Dim Folder As Object
Dim file As Object
Dim Files As Object


'Populate cboSOperation
Set FSO = CreateObject("Scripting.FileSystemObject")
Set this = ActiveWorkbook
Set sFolder = "C:\Ag Valley\Tracker"

If sFolder < "" Then
Set Folder = FSO.GetFolder(sFolder)
Set Files = Folder.Files
For Each file In Files
If file.Type = "File Folder" Then
cboSOperation.AddItem file.Name
End If
Next file
End If

Set FSO = Nothing

'Find folders to populate cboSGrower
Set FSO1 = CreateObject("Scripting.FileSystemObject")
Set this = ActiveWorkbook
Set s1Folder = this.cboSOperation.Value

If s1Folder < "" Then
Set Folder = FSO1.GetFolder(s1Folder)
Set Files = Folder.Files
For Each file In Files
If file.Type = "File Folder" Then
cboSGrower.AddItem file.Name
End If
Next file
End If

Set FSO1 = Nothing

'Find folders to populate cboSYear
Set FSO2 = CreateObject("Scripting.FileSystemObject")
Set this = ActiveWorkbook
Set s2Folder = this.cboSGrower.Value

If s2Folder < "" Then
Set Folder = FSO2.GetFolder(s2Folder)
Set Files = Folder.Files
For Each file In Files
If file.Type = "File Folder" Then
cboSYear.AddItem file.Name
End If
Next file
End If

Set FSO2 = Nothing

'Find Excel files to populate cboSFile
Set FSO3 = CreateObject("Scripting.FileSystemObject")
Set this = ActiveWorkbook
Set s3Folder = this.cboSYear.Value

If s3Folder < "" Then
Set Folder = FSO3.GetFolder(s3Folder)
Set Files = Folder.Files
For Each file In Files
If file.Type = "Microsoft Excel Worksheet" Then
cboSFile.AddItem file.Name
End If
Next file
End If

Set FSO3 = Nothing
--
Tyrell Fickenscher
Plant Manager / Agronomist