H
hhholmes61
When a user double clicks a combo box, a form opens (frmItems).
At the module level of frmItems, these are defined:
Dim CurrentControl As Control
Dim CurrentForm As Form
The OnLoad event of frmItems:
1. Identifies the control that was clicked
Set CurrentControl = Screen.ActiveControl
2. Identifies the form the control is in (whether a main form or a subform)
Dim myControl As Control
Set myControl = Screen.ActiveForm.ActiveControl
If TypeName(myControl) = "SubForm" Then
'it's a subform
Set CurrentForm = Screen.ActiveControl.Parent
Else
'it's not a subform
Set CurrentForm = Screen.ActiveForm
End If
When I close frmItems (a command button), I would like to requery the combo box that was originally clicked (the active control).
This works if the combo box was *not* on a subform:
Forms(CurrentForm.Name).Controls(CurrentControl.Name).Requery
DoCmd.Close acForm, "frmItems"
But it fails if the combo box was on a subform (for obvious reasons). How can I modify the code so it works when a subform is involved?
Thank you.
At the module level of frmItems, these are defined:
Dim CurrentControl As Control
Dim CurrentForm As Form
The OnLoad event of frmItems:
1. Identifies the control that was clicked
Set CurrentControl = Screen.ActiveControl
2. Identifies the form the control is in (whether a main form or a subform)
Dim myControl As Control
Set myControl = Screen.ActiveForm.ActiveControl
If TypeName(myControl) = "SubForm" Then
'it's a subform
Set CurrentForm = Screen.ActiveControl.Parent
Else
'it's not a subform
Set CurrentForm = Screen.ActiveForm
End If
When I close frmItems (a command button), I would like to requery the combo box that was originally clicked (the active control).
This works if the combo box was *not* on a subform:
Forms(CurrentForm.Name).Controls(CurrentControl.Name).Requery
DoCmd.Close acForm, "frmItems"
But it fails if the combo box was on a subform (for obvious reasons). How can I modify the code so it works when a subform is involved?
Thank you.