How to hide a subform within a subform?

S

Sam Kuo

I have a subform (sfStaffList_DataEntry) inside another subform
(sfCompanyFile). I'd like to click a command button (cbCancelAddNewStaff) in
sfStaffList_DataEntry and set focus back to a Originator combo box in
sfCompanyFile and hide sfStaffList_DataEntry.

I attempted with the code below, but it didn't work. Can anyone please help?
Many thanks

Private Sub cbCancelAddNewStaff_Click()
' Set focus back to Originator combo box in sfCompanyFile
Originator.SetFocus
' Hide sfStaffList_DataEntry
sfStaffList_DataEntry.Visible = False
End Sub
 
K

Ken Snell [MVP]

Change this line

Originator.SetFocus


to this:

Me.Parent.Originator.SetFocus
 
J

John Vinson

I have a subform (sfStaffList_DataEntry) inside another subform
(sfCompanyFile). I'd like to click a command button (cbCancelAddNewStaff) in
sfStaffList_DataEntry and set focus back to a Originator combo box in
sfCompanyFile and hide sfStaffList_DataEntry.

I attempted with the code below, but it didn't work. Can anyone please help?
Many thanks

Private Sub cbCancelAddNewStaff_Click()
' Set focus back to Originator combo box in sfCompanyFile
Originator.SetFocus
' Hide sfStaffList_DataEntry
sfStaffList_DataEntry.Visible = False
End Sub

You can't make a control visible while it's got the focus. I'd
suggest:

Parent.SetFocus ' set focus to the stCompanyFile subform
Parent!Originator.SetFocus ' then to the combo

then set the subform's visibility in the GotFocus event of Originator.

John W. Vinson[MVP]
 
S

Sam Kuo

Excellent! Thanks alot, Ken and John :)

John Vinson said:
You can't make a control visible while it's got the focus. I'd
suggest:

Parent.SetFocus ' set focus to the stCompanyFile subform
Parent!Originator.SetFocus ' then to the combo

then set the subform's visibility in the GotFocus event of Originator.

John W. Vinson[MVP]
 
Top