WithEvents subform

ClaraBarton

Registered User.
Local time
Today, 04:43
Joined
Oct 14, 2019
Messages
584
I have a main form with a subform.

Code:
Private WithEvents subFrm As Access.Form

Private Sub Form_Open(Cancel As Integer)
   ' set withevents variable to the subform object
   Set subFrm = Me.fsubDetail.Form
   ' ensure subform object raises Current event
   subFrm.OnCurrent = "[Event Procedure]"
End Sub
When the current event runs on the subform, I want a control on the parent form to become active but It can't seem to find it.
Since this code is on the parent form, how should the following code be addressed:
Code:
Private Sub subFrm_Current()
 On Error GoTo errlbl
 Dim strKey As String

   strKey = "IT" & Me.ItemID
       TVW.TreeView.Nodes(strKey).Selected = True  'Element not found
       TVW.TreeView.SelectedItem.EnsureVisible
       TVW.TreeView.DropHighlight = Me.TVW.SelectedNode

  Exit Sub
I've tried Me.Parent...
and Form.MainForm...
neither works
 
AARRGH!!! Do you know how long I've been staring and messing with this? Thank you so much!!!
 
When the current event runs on the subform, I want a control on the parent form to become active but It can't seem to find it.
This will create a loop. You cannot have both forms retain focus at the same time. When you move focus from the subform to the mainform, Access will save the subform if it is dirty and put the focus into the main form. Then you click in the subform and your code saves the subform record if it is dirty and puts the focus back into the main form.
 
This works because the main form is only a treeview for selecting records. The only change is changing the focus.
 

Users who are viewing this thread

Back
Top Bottom