Move or Remove focus from open form (1 Viewer)

MsAccessNL

Member
Local time
Today, 10:42
Joined
Aug 27, 2022
Messages
184
When I run these two commands: "DoCmd.RunCommand acCmdLayoutView, DoCmd.RunCommand acCmdFormView" from a cmdButton on the mainform it will work but from a subform it doesn't. When I move the focus to another openform, the docmd works. My question is to remove the focus from the main form (if no other form is open). I was thinking about setting the focus to the Menubar or the applicationwindow? Or maybe another solution to have the DoCmd.RunCommand acCmdLayoutView work from a button on a subform?
 

Minty

AWF VIP
Local time
Today, 09:42
Joined
Jul 26, 2013
Messages
10,371
You can't set focus to a form if it has any controls on it.

The layout option isn't available for a subform as it is simply a control on the main form.
You would have to set focus to a control on the parent form to get to layout mode.

But I have to ask why - surely a form layout shouldn't be being adjusted by the end user unless it's possibly a datasheet view?
 

MsAccessNL

Member
Local time
Today, 10:42
Joined
Aug 27, 2022
Messages
184
I still get an error when i set the focus to a control on the main form first.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:42
Joined
Oct 29, 2018
Messages
21,473
I still get an error when i set the focus to a control on the main form first.
I'm not getting an error at all. However, when I go to Layout View, I can't click on any buttons. If so, what's the use? Just curious...
 

MsAccessNL

Member
Local time
Today, 10:42
Joined
Aug 27, 2022
Messages
184
I'm not getting an error at all. However, when I go to Layout View, I can't click on any buttons. If so, what's the use? Just curious...
Strange, what is your code to set the focus to the control on the main form?

Reason: i think i found an easy way to create an Accordeon table/subform view (like on websites) I have to overcome a view small problems like this one.
 

Minty

AWF VIP
Local time
Today, 09:42
Joined
Jul 26, 2013
Messages
10,371
How are trying to set focus on the main form?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:42
Joined
Feb 19, 2002
Messages
43,275
Why would you ever put a form that the user is using into layout view? users don't get to modify objects!!!!!!!!!!!!!!!! If you want to remove focus from the only open form, where would you want it to go? The question makes no sense.
 

MsAccessNL

Member
Local time
Today, 10:42
Joined
Aug 27, 2022
Messages
184
Breathe, meditate and breathe again. I love you to. The reason i want to do these two commands is not the issue, it would take to much time to explain. (And the user must be lighting fast to change the object between these two commands..) But Please, let’s keep the reply’s restricted to possible solutions.
 

Users who are viewing this thread

Top Bottom