Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set visible = false from within subform 1

Status
Not open for further replies.

LARiot

Programmer
Feb 7, 2007
232
Hi. Thanks for looking at this. Please read this (and all questions) carefully before replying. Thanks.

I'm trying to set subform visible property to false from event of command button that exists inside of subform. I'm getting "2165 You can't hide a control that has the focus". And yes I've tried changing the focuse but since the code is being executed from the button in the subform, the focus jumps right back before executing the next line.

Long story short:

How do you set subform visible property to false from with subform?

-Nima
"Pluralitas non est ponenda sine necessitate", i.e., "Plurality is not to be posited without necessity" aka K.I.S.S. (Keep It Short and Simple) -- Ockham's Razor
 
A guess here, you tried [tt]
Me.Visible = False[/tt]
and that errors.

Did you try:[tt]
Me.Hide [/tt]?

Have fun.

---- Andy
 
Code:
Me.hide

gives me:

Compile error:

Method or data member not found

Hide doesn't show up in auto list members after I type "me."

-Nima
"Pluralitas non est ponenda sine necessitate", i.e., "Plurality is not to be posited without necessity" aka K.I.S.S. (Keep It Short and Simple) -- Ockham's Razor
 
Try:

For the OnClick event of the button on the sub-form...
Code:
Private Sub Command0_Click()
[indent]DoCmd.Echo False[/indent]
[indent]Me.Parent.Tag = "hide"[/indent]
[indent][COLOR=green]'this is some control on the parent form which will receive focus[/color][/indent] 
[indent]Me.Parent.Controls(1).SetFocus[/indent] 
End Sub

For the GotFocus event of the control on the parent form...
Code:
Private Sub Command2_GotFocus()[indent]If Me.Tag = "hide" Then[indent][COLOR=green]'This is the sub-form control[/color]
Me.Controls(0).Visible = False
Me.Tag = ""
[/indent]
End If
[/indent]
[indent]DoCmd.Echo True[/indent]
End Sub

Were it me, I would make the control on the parent form some very small button or something which will not be accidentally clicked on, and cannot be tabbed to.

Hope this helps!

gtg.jpg

GTG
 
I've revised my answer unnecessarily. This is why I call myself a geek.

For the OnClick event of the button on the sub-form...
Code:
[COLOR=blue]Private Sub[/color] Command0_Click()
    
[COLOR=blue]On Error GoTo[/color] click_Error
    [COLOR=green]'stop screen updates[/color]
    DoCmd.Echo [COLOR=blue]False[/color]
    [COLOR=green]'set the tag property[/color]
    Me.Parent.Tag = "hide"
    [COLOR=green]'this is some control on the parent form which will receive focus[/color]
    Me.Parent.Controls(1).SetFocus

click_Exit:
    [COLOR=blue]Exit Sub[/color]

click_Error:
    [COLOR=blue]If[/color] Err.Number = 2452 [COLOR=blue]Then[/color]
        MsgBox "It appears you have opened a sub-form without its parent.", vbOKOnly
        DoCmd.Close acForm, Me.Name, acSaveNo
    [COLOR=blue]End If[/color]
    Err.Clear
    DoCmd.Echo [COLOR=blue]True[/color]
[COLOR=blue]End Sub[/color]

For the GotFocus event of the control on the parent form...
Code:
[COLOR=blue]Private Sub[/color] Command2_GotFocus()
    [COLOR=blue]If[/color] Me.Tag = "hide" [COLOR=blue]Then[/color]
        [COLOR=green]'This is the sub-form control[/color]
        Me.Controls(0).Visible = [COLOR=blue]False[/color]
        Me.Tag = ""
    [COLOR=blue]End If[/color]
    DoCmd.Echo [COLOR=blue]True[/color]
[COLOR=blue]End Sub[/color]

There, now it's a little more robust. Have fun!

gtg.jpg

GTG
 
GregTheGeek: That pretty much did the trick. I just created a button to set subform.visible = false on both click and got focus.

I left the button available to user (instead of making it invisible) so if they want to just make the subform disappear, they can. Also no tab stop so no accidental got focus event being set off.

-Nima
"Pluralitas non est ponenda sine necessitate", i.e., "Plurality is not to be posited without necessity" aka K.I.S.S. (Keep It Short and Simple) -- Ockham's Razor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top