Can't Move Focus to SubForm

Highworth

New member
Local time
Today, 13:11
Joined
Sep 21, 2012
Messages
7
Hi, I have a form [frmDBT] that has a Tab Control with two pages, Threat (Page Index 0) and System (Page Index 1). The Threat page has four subforms and everything works well. I am able to navigate from the main form and the subforms on the page without difficulty. I hid blank text boxes inside the subforms with On Got Focus event procedures. The event procedures for the four subforms are:

1st subform: [frmsubScenario]
Parent.SetFocus
Parent.frmsubProbability.SetFocus
Parent.frmsubProbability!ProbabilityRating.SetFocus

2nd subform:[frmsubProbability]
Me.Parent.Rc1.SetFocus

3rd subform: [frmsubTree]
Parent.SetFocus
Parent.frmsubAttatchment.SetFocus
Parent.frmsubAttachment!Attachment.SetFocus

4th subform: [frmsubAttachment]
Me.Parent.Nomenclature.SetFocus

(I excluded the Private Sub Setfocus... and End Sub from the Event Procedures examples to save space on this post.)

The Second page, System, has problems. I can tab through all of the fields one time with no errors, but when I start to cycle through the fields a second time on the same record or begin cycling through the fields on a new record I get half way through and then get a run-time error 2110 that access can't move the focus to the control frmAttachments.

This page consists of one form frmsubTarget, which contains two additional forms: frmsubNarrative and frmsubOtherAttachments.

Similarly to the Threat page, I hid blank text boxes inside the subforms with On Got Focus event procedures. The event procedures for the two subforms are:

1st subform: [frmsubNarrative]
Parent!frmsubOtherAttachments.SetFocus
Parent!frmsubOtherAttachments.Form!OtherAttachment.SetFocus

2nd subform: [frmsubOtherAttachments]
Me.Parent.OtherName.SetFocus

The problem appears to be with the event procedure within the first subform. I have tried various things such as Parent.frmsubOtherAttachments.SetFocus
Parent.frmsubOtherAttachments.Form!OtherAttachment.SetFocus
and
Parent.Setfocus
Parent.frmsubOtherAttachments.SetFocusParent.frmsubOtherAttachments.Form!OtherAttachment.SetFocus

and
Forms!frmsubOtherAttachments.Form.SetFocus
Forms!frmsubOtherAttachments.form.controls(1).SetFocus

I also tried to incorporate this sample code
Forms(strForm).Controls(strSubform).Form.Controls(strControl).Value
that I borrowed from btabdevelopment but I couldn't figure out how to modify it correctly.

I would appreciate any suggestions, comments, references, etc that will assist me in figuring out this problem. I'm sure that this has been solved within this forum or others but I have not been able to find it yet.

Thanks,
Highworth
 
Last edited:
OK, so I thought that everything worked OK on the first page but as I was tabbing throught the fields for a second time I encountered a run-time error 2110 "Can't move focus to the control frmsubProbability" The code is
Private Sub txtRelay_GotFocus()
Parent.SetFocus
Parent.frmsubProbability.SetFocus
Parent.frmsubProbability!ProbabilityRating.SetFocus
End Sub
 
The key with subforms is to remember to use the correct syntax. Now, if the subform control (control on the parent that houses/displays the subform) has the exact same name as the subform then it isn't necessary to use the .Form. part that I'm about to show, but it isn't going to hurt and it would make it easier to be consistent.

The correct syntax would be:
Code:
Me.Parent.SubformControlNameHere.Form.SetFocus
Me.Parent.SubformControlNameHere.Form.ProbabilityRating.SetFocus
Note the use of .Form. in there. That tells Access that you want a property or method on the form and not on the subform control. But you still have to use the subform control name.
 
Thank You boblarson. I'm going to give it a shot now and report my results in a few.
Highworth
 
Bob, Thanks again for your reply. You appear to be the guru on this topic so I know I'm either not explaining the problem properly or I'm coding incorrectly. I changed the syntax per your recommendation (The subform [frmsubProbability] is located in a control called frmsubProbability.) However, when I tab through the fields I receive a Run-time error '2449' There is an invalid method in an expression. This error occurs as soon as I tab into the first subform. My new code is:
Private Sub txtRelay_GotFocus()
Me.Parent.frmsubProbability.Form.SetFocus
Me.Parent.frmsubProbability.Form.ProbabilityRating.SetFocus
End Sub

Me.Parent.frmsubProbability.Form.SetFocus is highlighted in the debugger.

The previous code allowed cycling through all fields and subforms with the tab key once and then it would crash prior to going into the 3rd subform.

Any suggestions on where I'm screwing this up? I've been working on this database with zero frame of reference, a few books, and this awesome forum but really have no idea what I'm doing. Learning a lot but confidence is low.
 
Bob, please find attached. Thanks.
Highworth
 
Last edited:
Re: Can't Move Focus to SubForm (on subsequent records)

I'm still trying different code options to get this to work. The strange thing to me is that everything works just the way I expect it to on the first record. When I tab from the last combo box on the main form for the first record and move into the first combo box on the main form for the second record all is well. When I tab into the first sub form, rather than focus moving to the first combo box in the sub form, it moves to the dummy text box that holds the GotFocus event code and triggers Run-time error’2110’ can’t move the focus to the control frmsubProbability. This also happens on the first record if I use the mouse to click back into the recalcitrant subform.
 

Users who are viewing this thread

Back
Top Bottom