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

Lost Focus and PopUp Forms

Status
Not open for further replies.

rookery

Programmer
Apr 4, 2002
384
GB
Why is it that when you open and close a pop-up form in code, when Access returns to the line immediately after the OpenForm command (after going round the houses with the On-Load event etc) it no longer recognises the "Me" qualifier in relation to the popup form?

"Me" now refers to the Form behind the pop-up window. This is still the case even if I hard-code and set focus to the pop-up form. The solution is simple enough but I want to know why this is happening. Theres no logic behind it!!
 
There is every bit of logic behind it.......

The Me keyword is shortcut that refers to the forms that current holds a system variable of Forms![name of Form].I Have Focus (not in thsoe words, but you get the picture).

So in you case, you open the main form (We'll call him frmMain). Me is the same as typing Forms![frmMain]. From frmMain, you open a pop-up form we'll call frmPopUp. The Me now refers to Forms![frmPopUp]. You then close frmPopUp, so Me returns to frmMain becuase he now has focus again....

As you can see, the logic is sound and secure....if you are having difficulties with the concept, you can write a whole appplication and never use the shortcut Me. Instead, always use Forms![Name of Form]![ctrl on Form].Property, but I think you will quickly come to apppreciate and understand the use of Me! Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Firstly apologies as my question was worded slightly wrong. The beginning should have read "Why is it that when you CLOSE AND OPEN..." rather than "...open and close...".

This is the situation: I have a pop-up Form open with the Main Form behind it. I then push a button on the pop-up and the code closes and then re-opens the pop-up Form. It is the code AFTER the OpenForm command that no longer recognises the "Me" qualifier. That is, "Me" now refers to the Main Form behind the open pop-up Form.

It is this that I cannot understand.
 
Ok.....that is a different story......Although I am not 100% sure on this...here's my thinking and reasoning behind this behavior.

Assumptions: The Main Form and Pop-Up form open. The Pop-Up form is not set to Modal. You have button on the Pop-Up form that has code similar to the following:

DoCmd.Close
DoCmd.Open "Name of Pop-up Form"

When you click on the button, the first part of the code runs....DoCmd.Close. The Pop-Up form is closed, and the Main Form remains. Since there is no where else for the focus to go, it goes to to the Main Form.

Next the DoCmd.Open line executes. Since this code is basically running from a cache now (as the Pop-Up form no longer exists), it executes, but does not return focus to the Pop-Up because the code is not being called from an existsing form.

Just my logic thinking....

You could probably circumvent this problem by simpy adding

Forms![name of pop-up form].SetFocus at the end of your code.....


Hope this makes things a bit clearer... Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
As per my first post, your suggestion that I set focus to the pop-up Form has no effect. Also the Modal property is set to Yes. A thought occurs to me: does that mean that when the Form is re-opened I'm unable to set Focus to it? However I like the explanation as to where the code is called from when the Form is closed.
 
Ok, let's throw another monkey in the wrench........You say the Modal property of the Pop-Up is set to yes....What is the Modal property of the Main Form??? If it is set to true, there's your problem.....you have passed focus to a form that will keep fcous until closed.

Looking at the help file o the Modal property, the focus cannot be changed until the form is closed, which we already know, but how does that apply to this "cached" code??? I don't know....

Just my thinking again, but perhaps because the code is running from a "cache" there is a normal rule breakdown....You are closing one modal form, forcing the focus to the main screen, then finishing the code from the closed form from cache to open another modal form....but the focus has already been moved due to the closing of the first modal form, and the new modal form is being called from a "ghost" code.....

Something to try.......try chanig the modal property of the Pop-Up to false and see what happens.... Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
The Modal property of the Main Form is set to False so unfortunately that rules that one out. The reason I havent set Modal to false on the pop-up is because I need to retain the behaviour in this particular circumstance (dont want users pushing buttons they shouldn't!).

However I think in the interests of science this little experiment should be explored! I'll let you know. Cheers for your interest so far.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top