Full Version: Moving focus off subform to hide
UtterAccess Forums > Microsoft® Access > Access Forms
Tygler1
Hi everyone,
I'm having a bit of a problem that should be simple. I have a command button on a form that unhides and hides a subform. When you click the button the subform appears and you can enter data. When you click the command buttton again I want the subform to hide.
My problem is that I'm getting that nasty "You can't hide ...while it has the focus". I have tried setting the focus back to the main form when you click the button but it doesn't seem to work! Can anyone see what I am missing???
Thanks
CODE
  
Private Sub cmdRoot_Click()
If Me.cmdRoot.Caption = "Hide Root Cause Form" Then
Me.SetFocus
DoCmd.GoToControl "txtFocus"
Forms!formwelcome!FormCAManagerNew!frmcaseNarrative.Form.Visible = False
Me.cmdRoot.Caption = "Show Root Cause Form"
Else
Me.cmdRoot.Caption = "Hide Root Cause Form"
Forms!formwelcome!FormCAManagerNew!frmcaseNarrative.Form.Visible = True
   End If
End Sub
MattJ
Try setting the focus to a control on the main form instead of the form itself
HTH
Matt
Tygler1
That is what I am trying to do...
When you click the command button (on the main form) to hide the subform. That is where I am trying to:
me.setfocus
gocmd.gotocontrol "txtfocus"
txtFocus is back on the main form. I am trying to get the button to move the focus back to txtFocus on the Main form before hiding the subform but it isn't working.
niesz
I would think that just clicking the command button itself would move the focus to the command button on the main form. Have you tried it without the two lines of code referenced above?
Tygler1
Yup. I've tried that too! I don't think a command button can have the focus...but I could be wrong!
niesz
Yes, they can.
Tygler1
OK...but it doesn't work!
It still says I can't hide the subform while it has the focus?
sredworb
Just wondering was gocmd a typo for docmd?

DoCmd.GoToControl "ControlName"

Will work for you..

Dont know about gocmd.

Sorry, read the code....my fault...
Edited by: sredworb on Thu May 4 10:10:57 EDT 2006.
niesz
Do you think you can post your DB? It seems like you have two nested subforms but I can't be sure.
Tygler1
sorry...yes THAT was a typo!
That I did just realize though is that the subform that I am trying to hide is ON a subform on my main form...So, it is actually a subsubform! The command button is on the main form.
Maybe that is where my problem lies?
jackb22
You want to show and hide the Subform Control, not the form within it. So try the following:
Private Sub cmdRoot_Click()
If Me.cmdRoot.Caption = "Hide Root Cause Form" Then
Me.SetFocus
Me!txtFocus.SetFocus
Forms!formwelcome!FormCAManagerNew!frmcaseNarrative.Visible = False
Me.cmdRoot.Caption = "Show Root Cause Form"
Else
Me.cmdRoot.Caption = "Hide Root Cause Form"
Forms!formwelcome!FormCAManagerNew!frmcaseNarrative.Visible = True
End If
End Sub
Jack
Tygler1
LOL....niesz...I must have noticed it just as you did!
My DB is too large and complicated to post!
sredworb
I dont think it should matter where the cmd button is, you can adjust the code to work..
Tygler1
Jack,
How is that code different from mine? I tried it and still got the error!
Tygler1
sredworb,
HOW do I adjust the code to get it to work....Sorry, THAT's what I can't figure out! I know the code needs to be altered...I just can't figure out how!
jackb22
Since it's a subsubform, try the following:
Private Sub cmdRoot_Click()
If Me.cmdRoot.Caption = "Hide Root Cause Form" Then
Me.SetFocus
Me!txtFocus.SetFocus
Forms!formwelcome!FormCAManagerNew.Form!frmcaseNarrative.Visible = False
Me.cmdRoot.Caption = "Show Root Cause Form"
Else
Me.cmdRoot.Caption = "Hide Root Cause Form"
Forms!formwelcome!FormCAManagerNew.Form!frmcaseNarrative.Visible = True
End If
End Sub
Jack
Tygler1
Jack,
ame error!
"You can't hide a control that has the focus!"
What am I missing?
jackb22
First make sure that FormCAManagerNew and frmcaseNarrative are Subform Control Names , which may not necessarily be the names of the forms themselves.
I think you have to set focus to a another control on the first subform in addition to the main form. So try the following:
Private Sub cmdRoot_Click()
Forms!formwelcome!FormCAManagerNew.SetFocus
Forms!formwelcome!FormCAManagerNew![SomeOtherControl].SetFocus
Forms!formwelcome.SetFocus
Forms!formwelcome!txtFocus.SetFocus
If Me.cmdRoot.Caption = "Hide Root Cause Form" Then
Forms!formwelcome!FormCAManagerNew.Form!frmcaseNarrative.Visible = False
Me.cmdRoot.Caption = "Show Root Cause Form"
Else
Me.cmdRoot.Caption = "Hide Root Cause Form"
Forms!formwelcome!FormCAManagerNew.Form!frmcaseNarrative.Visible = True
End If
End Sub
Jack
sredworb
I have a main form with about 7 other forms on it, I hide most of them..
Can you upload your db "stripped down" and I'll try to do to yours what i did for mine, easier to do it then to explain it...
Let me know..
Jerry
jackb22
I need to make one correction to my previous code:
Private Sub cmdRoot_Click()
Forms!formwelcome!FormCAManagerNew.SetFocus
Forms!formwelcome!FormCAManagerNew.Form![SomeOtherControl].SetFocus
Forms!formwelcome.SetFocus
Forms!formwelcome!txtFocus.SetFocus
If Me.cmdRoot.Caption = "Hide Root Cause Form" Then
Forms!formwelcome!FormCAManagerNew.Form!frmcaseNarrative.Visible = False
Me.cmdRoot.Caption = "Show Root Cause Form"
Else
Me.cmdRoot.Caption = "Hide Root Cause Form"
Forms!formwelcome!FormCAManagerNew.Form!frmcaseNarrative.Visible = True
End If
End Sub
Jack
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.