A
AFSSkier
I have 4 FormControl CboBoxes on a sheet (not UserForm). These are
dynamically populated by reading unique ListFillRange values from 4 different
sheets that are connected to 4 separate Access Queries from a category
hierarchy (Dept, Cat, SubCat, ProdModule). I have some code that basically
does what it is suppose to do, by cascading through each of the CboBoxes. By
doing a Requery through the 4 separate Access Query sheets (Dept, Cat,
SubCat, ProdModule).
The problem I can’t overcome is when the user does a “RefreshAll†the 2nd,
3rd & 4th CboBoxes default to 0. The user would like to have the CboBoxes to
remain selected to their choices for next week’s “RefreshAllâ€.
Here’s basically how I have it working:
When the LinkCell to “DeptSheet†changes in the 1st CboBox “cboDEPTâ€, it
fires off a requery of the Access Query to repopulate CatSheet for the 2nd
CboBox “cboCatâ€. This gives cboCat a cascading effect. As the user chooses
one of the records from the list of categories that correspond to the
“GROCERY†dept, the LinkCell “CatSheet†changes in the 2nd CboBox “cboCatâ€,
it fires off a requery of the Access Query to repopulate SubCatSheet for the
3rd CboBox “cboSubCatâ€, etc, etc cascading through to the final CboBox
cboProdMod.
VBA Code:
Private Sub cboDept_Change()
'For example, when the Department "GROCERY" is chosen in CboDept
' CatSheet Requeries to repopulate the list for cboCat
'providing a list of "GROCERY" Categories.
cboCat.ListIndex = 0
End Sub
Private Sub cboCat_Change()
'For example, when the Category for "BABY FOOD" is chosen in CboCat
' SubCatSheet Requeries to repopulate the list for cboSubCat
'providing a list of "BABY FOOD" SubCategories.
cboSubCat.ListIndex = 0
End Sub
Private Sub cboSubCat_Change()
'For example, when the SubCategory for "INFANT FORMULAS" is chosen in
CboSubCat
' ProdModSheet Requeries to repopulate the list for cboProdMod
'providing a list of "INFANT FORMULAS" Product Modules.
cboProdMod.ListIndex = 0
End Sub
Private Sub cboDept_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'This resets cboDept to the top of the list "DEPT".
cboDept.ListIndex = 0
End Sub
I was also wondering, is there a better approach to this in Excel, like on a
VBAS User Form? I've read several other posts & even looked at the Data
Validations at http://www.contextures.com. But that does not work for my
application.
I have done this many times on an Access form with the following code:
Private Sub cboDEPT_AfterUpdate()
Me.cboCAT.Requery
Me.cboSUBCAT.Requery
Me.cboPRODMOD.Requery
End Sub
Private Sub CAT_AfterUpdate()
Me.SUBCAT.Requery
Me.PRODMOD.Requery
End Sub
Private Sub SUBCAT_AfterUpdate()
Me.PRODMOD.Requery
End Sub
dynamically populated by reading unique ListFillRange values from 4 different
sheets that are connected to 4 separate Access Queries from a category
hierarchy (Dept, Cat, SubCat, ProdModule). I have some code that basically
does what it is suppose to do, by cascading through each of the CboBoxes. By
doing a Requery through the 4 separate Access Query sheets (Dept, Cat,
SubCat, ProdModule).
The problem I can’t overcome is when the user does a “RefreshAll†the 2nd,
3rd & 4th CboBoxes default to 0. The user would like to have the CboBoxes to
remain selected to their choices for next week’s “RefreshAllâ€.
Here’s basically how I have it working:
When the LinkCell to “DeptSheet†changes in the 1st CboBox “cboDEPTâ€, it
fires off a requery of the Access Query to repopulate CatSheet for the 2nd
CboBox “cboCatâ€. This gives cboCat a cascading effect. As the user chooses
one of the records from the list of categories that correspond to the
“GROCERY†dept, the LinkCell “CatSheet†changes in the 2nd CboBox “cboCatâ€,
it fires off a requery of the Access Query to repopulate SubCatSheet for the
3rd CboBox “cboSubCatâ€, etc, etc cascading through to the final CboBox
cboProdMod.
VBA Code:
Private Sub cboDept_Change()
'For example, when the Department "GROCERY" is chosen in CboDept
' CatSheet Requeries to repopulate the list for cboCat
'providing a list of "GROCERY" Categories.
cboCat.ListIndex = 0
End Sub
Private Sub cboCat_Change()
'For example, when the Category for "BABY FOOD" is chosen in CboCat
' SubCatSheet Requeries to repopulate the list for cboSubCat
'providing a list of "BABY FOOD" SubCategories.
cboSubCat.ListIndex = 0
End Sub
Private Sub cboSubCat_Change()
'For example, when the SubCategory for "INFANT FORMULAS" is chosen in
CboSubCat
' ProdModSheet Requeries to repopulate the list for cboProdMod
'providing a list of "INFANT FORMULAS" Product Modules.
cboProdMod.ListIndex = 0
End Sub
Private Sub cboDept_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'This resets cboDept to the top of the list "DEPT".
cboDept.ListIndex = 0
End Sub
I was also wondering, is there a better approach to this in Excel, like on a
VBAS User Form? I've read several other posts & even looked at the Data
Validations at http://www.contextures.com. But that does not work for my
application.
I have done this many times on an Access form with the following code:
Private Sub cboDEPT_AfterUpdate()
Me.cboCAT.Requery
Me.cboSUBCAT.Requery
Me.cboPRODMOD.Requery
End Sub
Private Sub CAT_AfterUpdate()
Me.SUBCAT.Requery
Me.PRODMOD.Requery
End Sub
Private Sub SUBCAT_AfterUpdate()
Me.PRODMOD.Requery
End Sub