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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set focus from subform to Main form, cannot go back to subform

Status
Not open for further replies.

duanecwilson

Programmer
Jul 15, 2005
26
US
I have a problem that is really wearing me out. It seems like I'm chasing my tail all day. I solve one problem only to introduce another. I have a form that sets focus immediately to a subform control. It works fine. Then, I tab through, and after being finished entering data in the fields, the focus is set back to the main form closebutton. That works fine. I had a problem when I clicked outside the last field as it would just jump to the close button. So I put a transparent control after the last text field so that would receive the focus and as soon as it got the focus, it would set the focus back to the main form closebutton. That way I could tab out of it and it would go to the close button and that worked fine and I could click out of it and that would work fine.

So after all that, now my new problem. After it sets focus back to the main form close button, I can never go back to the subform. I can click on other controls on the main form, but as soon as I click ANYWHERE on the subform, the focus jumps right back to the main form close button. What is going on here? It seems as once it goes to that close button from the transparent control on the subform, no matter what you do on the subform again, the focus goes right back to the close button.

Duane Wilson
 
Set the focus to the first field of the subform before setting the focus to the close button.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I don't understand. Are you talking about in the got focus event of the transparent button where I set focus to the close button I should have 2 commands in a row, first set focus to the subform field and then setting focus to the close button?

Duane Wilson
 
OK. Now I'm confused. I did what you said, and it DOES work! The only thing is, I don't understand why. Can somebody tell me? I need to understand events better - that's part of the problem. I understand which events happen in what order when you click something, but I don't understand suppose you click from one sub-form button to another, or whatever - what is the order of events? For example, when I click another button, which code gets executed first, etc. I tried to step through the code, but as soon as the close button had before got the focus, it stopped stepping through. I just want to understand better.

Duane Wilson
 

As I understand it, you have code set on your phantom control to send you to the main control/close button. That means that the phantom control is the last control on your subform to have focus. When you try to move from mainform to subform, the control on the subform that last had focus receives focus again, and sends you immediately back to the mainform/closebutton! By setting focus to another control on your subform. then moving to the mainform/closebutton, that other control receives focus when you move back to the subform, so you break the closed loop you'd created!

Linq

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 

By the way, it's refreshing to find someone who's not just satisfied with finding a solution to their problem, but who actually wants to understand the solution!

Linq

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thank you. That helps a lot. I had no way of knowing that the program "remembers" where the last focus was, or even what the purpose of that is. I'm not sure of the order of VBA code execution is either. In this situation, it would "seem" that setting the focus to the subform control first would cause the got focus event of that control to fire and who knows the consequence of that. I guess a good reading of MS Access "theory" is in order as bad as that word sounds. Any ideas for a good book on the subject?
I know about "theory" from music as I am a pianist. It is amazing how much better you can play when you just sit down in a classroom or read a book and understand theory. I am sure it is with Access or any computer language, as well. So, if anyone knows of a good nuts and bolts theory book, (or web site), I am game for it. Thanks for all the help and explanation.

Duane Wilson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top