SetFocus from Subform to ParentForm

G

Guest

Hi
I have a form which has feilds and a command button in the header and in the
details it has a subform.

In the subform there are fields and a command button.

When I click on the command button from the parent form I can setfocud on
one of the fields in the subform.

When i click on the command button from the subform I cannot setfocus on a
field in the Parent form.

Below is the code I have attached to the command button on the subform.

Forms!frm_Update1st.SetFocus
Forms!frm_Update1st!Store.SetFocus
Form_frm_Update2nd.Visible = False

Thank you
Noemi
 
G

Guest

Hi Alex
It keeps focus on teh command button on the subform rather than setting
focus on the Store text combox for the parent form.

Anyidea's why this is??
 
G

Guest

The set focus should work, and there are few option on doing that
I tried Alex method and it works

Another way

Me.Parent.Store.SetFocus

I would check if the field you set the focus to has any code in it that
might set the focus back to the sub form, like the GotFocus event.
 
G

Guest

And as another 'tester' try this as well

'---set the focus to the form first
me.Parent.setfocus
Me.Parent.Store.SetFocus
 
G

Guest

It still doesn't work, the focus stays on the command button in the subform.

I have attached the code for both forms with an explanation of what happens.

Parent Form:

Private Sub Form_Load()
Form_frm_Update2nd.Visible = False
DoCmd.GoToRecord , , acNewRec
End Sub

This is the command button which populates a table, makes the subform
visible and adds ID number to variable
Public Sub cdmAdd_Click()
On Error GoTo Err_cdmAdd_Click

dbID = ID
Form_frm_Update2nd.Visible = True
Form_frm_Update2nd.ID = dbID
Forms!frm_Update1st!frm_Update2nd.SetFocus
Forms!frm_Update1st!frm_Update2nd.Form!ExpiryDate.SetFocus

Exit_cdmAdd_Click:
Exit Sub

Err_cdmAdd_Click:
MsgBox Err.Description
Resume Exit_cdmAdd_Click


SubForm code:
Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub

This is the command button which updates another table and should set the
focus back to the Parent form, however it doesn't work as the focus stays on
the button.
Private Sub cmdAddDetails_Click()
On Error GoTo Err_cmdAddDetails_Click

Me.Parent.SetFocus
Me.Parent.Store.SetFocus
Me.Parent.Form_frm_Update2nd.Visible = False

Exit_cmdAddDetails_Click:
Exit Sub

Err_cmdAddDetails_Click:
MsgBox Err.Description
Resume Exit_cmdAddDetails_Click

End Sub


I hope soemone can help with this.
Thanks
Noemi
 

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