Switching Focus Between Forms

accvbalearner

Registered User.
Local time
Today, 17:50
Joined
Jan 3, 2013
Messages
42
Hi All,

Thanks in advance for the help everyone here is so great at providing!

My issue today is that I am trying to switch the focus between two forms. One form is the main data entry form for a particular task, the second form is a popup type form for reference only. When a user selects a Work Order # for example a little window will popup giving a few essential details regarding the Work Order selected. I would like for the popup to open but keep the focus on the form that opened the popup.

Initially, I had the popup as a subform and everything was working great, but I ran out of room on the form for users with a lower screen resolution, so I need this form to open up in a separate window, show the data but keep the focus on the main form, this popup also needs to stay open until the record on the main form is complete, then it will close and open again when a new record is started. Data will never be entered into or modified in the popup, its for reference only.

To get the Popup Form to Open I use this code:

DoCmd.OpenForm "frmName2", , , fmCap3, acFormReadOnly

I have tried the following code in OnLoad, OnGotFocus and OnOpen Events for the Popup Form and none are working, :

I have substituted frmName and frmControlName for the actuals used in the Popup Form.

Example 1
With Forms(frmName)
.SetFocus
.Controls([frmControlName]).SetFocus
End With

Example 2
Forms!(frmName).Form.frmControlName.Setfocus

Example 3
Me.frmName.Form.frmControlName.SetFocus

Example 4
Forms.frmName.Form.frmControlName.Setfocus




Take Care,
accvbalearner
 
If you can't get the popup to work the way you want, one technique I have used for subforms is to set the width and /or height of the subform to 0 (which effectively hides it) and then depending on where the user is on the main form move it 'out of the way'

For example if your user is completing fields down the left of the screen so you want the subform on the right - code in the got focus event for a left of form control would be

Code:
subform.width=1440 * 2 'convert twips to inches
Subform.left=insidewidth-subform.width
subform.height=1440 * 1 'convert twips to inches
subform.top=1 'for top right or insideheight-subform.height for bottom right

If you have a number of controls - put the above into a procedure which is called by each control

You can also do things using the mousedown and mouse move events to enable the user to drag the form to another area.
 
CJ_London,

Thanks for the reply, but I'm not sure how to apply what you are recommending. In the situation I have now, I have two forms, one is the primary form where data is added. The second form is an actual form, not a subform, that provides a summary of a work order. Once the user selects a work order from a list in the primary form, the second form pops up showing the summary information. This part is working really well, the problem is that I can't move the focus back to the primary form to continue entering data. I have tried all of the variants that I can think of to return the focus to the other form but none are working.

I have placed:
Forms![PrimaryFormName].Form.[NextBoxName].SetFocus
in the OnOpen, OnGotFocus, & OnEnter Events of the second form, but the cursor just stays in the second form. I need it to return to the Primary Form after the Second Form opens. I have disabled all Allow Additions, Deletions, etc. for the Second Form so once its opened the user can't enter anything anyway.

Am I opening up the second form incorrectly?

To open the second form, on the OnLostFocus event in the primary form I am using:
DoCmd.OpenForm "SecondFormName", , , "[WO#] = " & "'123'", acFormReadOnly
Should it somehow be a subform just in a different window? I've read through your code and, to me, it looks like you are just telling this second window to open in a certain spot on the screen, how does it move the cursor back to the primary form?

Any help you can provide is much appreciated!

Take Care,
accvbalearner
 
Sounds like you need object path syntax that jumps between parent and child forms. Examples:

How to SetFocus to a specific control on a Subform of a Form
http://www.access-programmers.co.uk/forums/showthread.php?t=221705#post1132324

Relocate Previously Selected Record in a Multiple Items Form
http://www.access-programmers.co.uk/forums/showthread.php?p=1178436#post1178436

The second post is where I learned that it is necessary to SetFocus to the subform first, then the specific control on the subform as a second LOC.

Hopefully these posts assist you with your specific situation.
 
I was just suggesting an alternative suggestion so you could get back to:

Initially, I had the popup as a subform and everything was working great
 
md_lueck,

Nice to hear from you again, you were a great help to me on another problem a while back I believe. I've followed your two links but they are both referring to a Subform. I've tried using the Me!Parent at the beginning of the statement, but it just gives me an error and prompts be to debug, I think its because the second form isn't a "subform" its just another form that summarizes data about an item selected in the first form, kind of like a report.

To me it seems like the second window that I have opening is acting like the Properties Window in Form Design, once you are in it you can't Tab out of it, you must click out. But it stays open when you are clicking/working around in your actual form. This isn't what I need to happen, I need it to be a window that a user can see but not click in, interact with etc. It's just contains reference data the User may need.

Would using a SplitForm be an answer to this problem?

Hope I haven't confused the issue too much.:confused:

Take Care,
accvbalearner
 
CJ_London,

Ok, sorry about that. Going back that way, might work but I don't have enough room on a screen for a User with <1280. I can't figure out how to do that though, because a User will need to see the info while they are entering data.

Thanks for the idea though!

Take Care,
accvbalearner
 
here is an example to test the principle.

Open form2 and click on any of the fields
 

Attachments

Oh... a sort of "always on top" much like the Windows Task Manager (Ctrl-Shift-Esc) even if it does not specifically have focus?

Form A opens Form B.
Form B should be able to set focus back to Form A as part of its Load event.

Even on the next LOC after the Form Open in Form A, Form A should be able to issue a Me.SetFocus.

Just a couple of misc things to try as I "think out typing" ;)
 
mdlueck,

Yes that is correct.
Form B should be able to set focus back to Form A as part of its Load event.
I can't figure out the correct VBA code syntax to set the focus back to Form A after Form B opens. I am using the Docmd.OpenForm on the OnLostFocus Event in Form A to Open Form B. I have even tried using the .SetFocus command there, but the cursors is still blinking over there in Form B and there is nothing I can do (Tab, Enter, etc.) to move back to Form A. The only way to get back to Form A is to click on Form A with the Mouse. When I do this, Form B stays open, which is what is supposed to happen, but I don't want the cursor to be there in the first place.

Thanks for your help and interest....

Take Care,
accvbalearner
 
CJ_London,

Thanks for the sample, I haven't had a chance to try it yet, I'll reply back when I get a chance to test it.

Take Care,
accvbalearner
 
I can't figure out the correct VBA code syntax to set the focus back to Form A after Form B opens.

Copied from code which involves dialog boxes, WithEvents Forms, and and and...

Code:
  'Copy of focus change code here since the various dialog boxes this report requires cause the Form event to complete ahead of time
  Call Forms("projectreports").Form.btnSelect.SetFocus
  Call Forms("projectreports").Form.tvProjectReports.SetFocus
 

Users who are viewing this thread

Back
Top Bottom