Full Version: Cant hide control that has focus
UtterAccess Forums > Microsoft® Access > Access Forms
I have an error that i can seem to get rid of here.
I have a tab control....one one of the tabs there is another tab control. On the first tab control i have a drop down control box that will allow me to bring up a record. i have an on click event for this box that setsfocus to it. i also have an after update event that will requery some list boxes and hide the second tab sheet.....however....when i am working on the second tab control and then go to back to the main page and select a new drop record from the drop down i am told that i cant hide control that has focus.
I thought that with the onclick event the focus would change from the second tab control back tot he first one.
any ideas what i am doing wrong!?
Jack Cowley
You have to move the focus from the current object... In code move the focus to any other control then in the next line move it to where you want it...
I dont understand......here is the code in order. The error is on the tabctrl.visible line.
Private Sub Combo95_Click()
End Sub
Private Sub Combo95_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[RepCompanyID] = " & Str(Nz(Me![Combo95], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Forms!frm_company.subfrm_Feedback.Form.TabCtl17.Visible = False
Forms!frm_company.frm_MissionPart.Form.subfrm_RepPart.Visible = False
Jack Cowley
Before the line of code to hide the tab control:
You may not be able to use 'Me', but will have to refer explicitly, as you are doing now, to the control you want to move the focus to...
Does that help?
Sorry it has taken me so long to get back with you....i have been outta town.
That doesnt work.
Otried both ways:
Both times it is still bringing up the error and highlighting the tbctl visisble line.
i dont understand why its not removing the focus from the form. it is possible that i cant remove the focus from a form once it has already been hidden...?...i.e. maybe i got to have a setfocus command in the buttons that hide/show the subforms...that way whatever form is visible will have the focus and if i click off it i can then move the focus???
Jack Cowley
Caleb -
It appears that you have a form/subform/subsubform. If that is correct then you need to know on which form the cursor is and then move it to whichever control on whichever form you want. To be sure you are correctly moving the cursor to the form/control you want take a look here for the correct syntax to move to or from a subform...
I hope this helps!
Humm....no matter what i try I can seem to get it to move the focus off the second tab sheet (2nd subfrm) and move it elsewhere. Its like it is locked in there. Maybe i have to do something different when relating to a tabcontrol instead of just a regular subfrm??
There is a screen shot to show the basic layout. everything works fine until i touch the second tab sheet...then i start getting the error.
The dropdown list which holds the afterupdate event that is giving me the error is not shown as it is on the main first sheet.
Jack Cowley
It is hard to know what is going on without actually seeing what it is you are trying to accomplish. Have you put a Stop or code break in your code so you can follow its execution to see exactly what is happening? At this point I think you should try that as that will show you what you code is doing on each line.... Give that a shot and let us know...
the code stops on the command to hide the tabctrl:
Forms!frm_company.subfrm_Feedback.Form.TabCtl17.Visible = False
This is the second tabctrl.
I am sorta new (patience please sad.gif), but how would a stop code show me anything different than that it is getting hung up on this part of the code??
Jack Cowley
You are right in that putting a stop in the code probably won't tell you much... Try this - remark out your current line of code then put a command button on the main form or the first subform. Set the command button to hide the tab control and see if that works. If it does then for whatever reason the code is not moving off the control... Have you done a compact and repair of the db? Have you tried importing everything into a new blank db? It is possible that something is corrupt in one of the forms and is causing this problem...
ang in there!!!
Nope....code doesnt work when in a command button either. tried it in two spots. get the exact same error and the same line highlighted. it will work (as did the after update command) as long as i dont click into the second tabctrl....once i do that....i am stuck. Once i enter second tabctrl....the focus is stuck in there.
I have complied and repaired.
Any other suggestions. It is clearly a prob moving the focus off that second tab control.
Jack Cowley
I have solved the problem... Do the following:
dd a text box to the subform but outside of the Tab Control. Let's call it Text5
Either add a command button to the tab control in question or add this code to the On Exit event of the control that you want to hide the Tab Control:
In the On Enter event of Text5 use this code:
Me.TabCtl17.Visible = False
You can also set the focus to Text5 from any subform or the main form and the Tab Control will be hidden...
This works for me so let me know if it works for you...
Thanks for taking the time with this.
When i follow that....i get an error when i leave the subform. It highlights not the code, but the acutal event.
Otried both a Me. routing and a Forms!.....routing.
Just to make sure i am putting the events in the right place:
I have an "on exit" command on the subfrm, directing it to set focus on a text box located on the subfrm, the text box has an on enter command of hide tab ctrl.
the code stops on the exit event.
any more ideas?
Jack Cowley
Caleb -
Take a look at the attached demo.... Hopefully it will get you on track....
I give up.
I have just discovered it is not just the tab sheet. It is any subfrm on the main frm. Once i am in it...i am stuck in it.
either have to think of something else...find the correct parent. command...or something. unfortunatly the click button wont work for me as it is adding a click that the user doesnt really need to do.
thanks for your help anyhow.
Jack Cowley
I just used a command button as it was easy, but you should be able to On Exit event of a control to trigger the code....
I am not sure why you can't leave a subform, but take a look here to see if that gives you an idea...
Ounderstand your frustration and I am not sure why you are having this much trouble...
Look at the article, try and and see if that helps...
Got it. Ended up placing an empty text box on each page, and then in my after update event, set the focus to these that were set with a hide command. works great. thanks for your help.
Jack Cowley
There you go! I knew you could solve it!!! Glad you are back on track and things are working as you want. Well done!!!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.