SetFocus to SubForm Not Working

whdyck

Registered User.
Local time
Today, 14:23
Joined
Aug 8, 2011
Messages
169
I'm using Access 2003.

I have a subform that is nested two levels deep (it has a parent and a grandparent form). In the AfterUpdate event of the subform, I requery the grandparent and parent forms (and restore to the same records displayed before the subform update), then I requery the subform and attempt to set the focus to the first field on the subform.

My code looks like this:

Code:
Private Sub Form_AfterUpdate()
On Error GoTo Err_Form_AfterUpdate
    Dim rs As Object
    Dim lngClaimBookmark, lngClaimPartyBookmark, lngLoadingID As Long
 
    'Set bookmarks
    lngClaimBookmark = Me.Parent.Parent.ClaimID
    lngClaimPartyBookmark = Me.Parent.ClaimPartyID
    lngLoadingBookmark = Me.LoadingID
 
    'Requery the Claim form
    Me.Parent.Parent.Requery
 
    'Go back to original Claim
    Set rs = Me.Parent.Parent.RecordsetClone
    rs.FindFirst "ClaimID = " & lngClaimBookmark
    Me.Parent.Parent.Bookmark = rs.Bookmark
 
    'Requery the ClaimParty form
    Me.Parent.Requery
 
    'Go back to the original ClaimParty
    Set rs = Me.Parent.RecordsetClone
    rs.FindFirst "ClaimPartyID = " & lngClaimPartyBookmark
    Me.Parent.Bookmark = rs.Bookmark
 
    'Requery the Loading form
    Me.Requery
 
    'Go back to the original Loading
    Set rs = Me.RecordsetClone
    rs.FindFirst "LoadingID = " & lngLoadingBookmark
    Me.Bookmark = rs.Bookmark
 
    Me.txtContractNumber.SetFocus
 
    Set rs = Nothing
 
Exit_Form_AfterUpdate:
    Exit Sub
 
Err_Form_AfterUpdate:
    Cancel = True
    MsgBox Err.Description
    Resume Exit_Form_AfterUpdate
 
End Sub

(I need to requery the parent forms because there are calculated fields on the parents that depend on data in the subform.)

All works fine *except* that the final SetFocus does not seem to work. In fact the focus is no longer even in the subform, but rather on the grandparent form. (After the above code runs, if I press tab, I'm tabbing through the grandparent form.)

Any idea why? I'd like to still be tabbing in the subform after this code runs.

Thanks for any help you can give.

Wayne
 
Hi

Maybe you could use Me.Recalc instead of Me.Requery
 
try this:

Forms!(GrandParentForm).SetFocus
Forms!(GrandParentForm).Form.ParentForm.SetFocus
Forms!(GrandParentForm).Form.(ParentForm).Form.ChildForm.SetFocus
 
try this:

Forms!(GrandParentForm).SetFocus
Forms!(GrandParentForm).Form.ParentForm.SetFocus
Forms!(GrandParentForm).Form.(ParentForm).Form.ChildForm.SetFocus

This worked beautifully. Thanks.

Actually, I had to tweak your code a bit. Here's what worked:

Code:
Forms!frmClaim.SetFocus
Forms!frmClaim!subClaimParty.SetFocus
Forms!frmClaim!subClaimParty!subLoading.SetFocus
 
Hi

Maybe you could use Me.Recalc instead of Me.Requery

Actually, I started out with a Recalc, but some of the dependent calc fields were not updating correctly, so I had to resort to a full Requery.
 

Users who are viewing this thread

Back
Top Bottom