Referring to control in the active subform


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.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top