Since your code only indicates the purposes of ComboBoxes 2 and 4, (Company and Department,) I can only speculate about the sequence of events your Users must go thru
Select a Year/Folder. (Dependent on "Roof") Changes Company List
Select a Company. (Dependent on "Roof") Changes Department List
Select a Department. (Dependent on "Roof") Changes Year/Folder List and Sets "Roof"
Repeat until possible choices quit changing.
Select from Combobox3.
I suggest that you start the User Experience from your ComboBox4, (My cboDepartment) And forget changing the list in it after the first selection since it itself and two of the other cbo Boxes are dependent on it.
Dim IsRoof As Boolean
Dim FolderSpec As String
Function GetsubFolderNames() As Variant
Dim FSO as Object
Dim Fldr As Variant
Dim SubFldrs As Variant
Dim i As Long
Dim Tmp As Variant
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fldr = fs.getfolder(folderspec)
Set SubFldrs = Fldr.SubFolders
ReDim(tmp, 1 to SubFldrs.Count)
For i = 1 to UBound(Tmp)
Tmp(i)= SubFlders(i).Name
Next
Set FSO = Nothing
Set Fldr = Nothing
Set SubFldrs = Nothing
GetSubFolderNames = Tmp
End Function
Private Sub cboYear_Change()
'ComboBox1
If IsRoof Then 'IsRoof will be false until the Roof department is later selected
folderspec = "M:\CA\"
Else
folderspec = "S:\PDF_Jobs\" & ComboBox1 & "\"
End If
On Error GoTo er:
cboComapny.List = GetSubFolderNames
Exit Sub
er: MsgBox " Wrong Year?"
End Sub
Private Sub cboCompany_Change()
'company combobox
If IsRoof Then 'IsRoof will be false until the Roof department is later selected
folderspec = "M:\CA\" & cboCompapny
Else
folderspec = "S:\PDF_Jobs\" & cboYear & "\" & cboCompany & "\"
End If
On Error GoTo er:
ComboBox3.List = GetSubFolderNames
Exit Sub
er: MsgBox "Typo or Company not Found"
End Sub
Private Sub cboDepartment_Change()
'Combobox4 = Department
'This is where IsRoof might become True
IsRoof = ComboBox4 = "Roof"
If IsRoof Then
folderspec = "M:\"
Else
folderspec = "S:\PDF_Jobs\"
End If
cboYear.List=GetSubFolderNames
End Sub
Private Sub ComboBox3_Change()
If IsRoof Then
Label9 = "M:\" & cboYear & "\" & cboCompany & "\" & ComboBox3 & "\"
Label30 = "M:\CA\Jobs2016\" & cboCompany
Else
Label9 = "S:\PDF_Jobs\" & cboYear & "\" & cboCompany & "\" & ComboBox3 & "\"
End If
End Sub