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!

Shift focus from usiform back to text in document 2

Status
Not open for further replies.

jimblamd

Technical User
Dec 26, 2006
3
US
I am using a usiform to modify or add to text in a document. After using a command button that then modifies the open document, I would like the focus back on the document not the userform. As it is, I need to click the document to return the focus. The uniform is being run as nonmodal.

any thoughts

thanks
 
Userforms, as such, are TopMost forms, and without disposing (unloading) the form, you must manually change the focus.

Of course, I'm usually wrong 99% of the time which would make me a great weatherman.

HTH

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Some questions:

1. How are you starting the userform?

2. Why do you have ShowModal = False? This is useful when you want to do as you are doing - click back to the document to get focus there.

3. What do you want to happen to the userform after the actions of the commandbutton?

If you are finished with the userform after the commandbutton actions, you do not need to have the userform as ShowModal = False. Simply unload the userform at the end of the commandbutton actions. Unload Me.

Otherwise, if you want to return focus to the document you can use Userform.Hide. The userform will disappear and focus will return to the document. However, the userform will of course NOT be unloaded, just hidden.

So you would need (if you want to get the userform back again) something to Show it again. You could have a separate procedure (set up to fire with a keyboard shortcut, or a toolbar icon) that does Userform.Show. This goes back to question #1. They could be one and the same.

The most important question, though, is #3 - what do you actually want the userform to do after the actions of the commandbutton?

Gerry
My paintings and sculpture
 
Thanks fumei

I am using the usiform as a source to add various text and to move around the document. For examble on a combobox i can move to a word and add a paragraph. I want the form to stay there to do it again. As is i have to shift the focus to the document manually.

if no other choice fine. I would have thought i could add code to a button etc. that returns the focus to the docuemnt like activewindow.setfocus but of course this does not work.

any case thanks for input.
 
OK, if the userform is to be on-going, then I re-suggest making a button, or keyboard shortcut, to use .Show. Then at the end of the commandbutton action, use .Hide. That way the focus WILL go to the document, but you can get the userform back again easily.

OR, and here is the likely solution for you, put:
Code:
Application.Activate
at the end of your commandbutton actions. This will shift focus to the document AND not hide the userform.

The only issue I see with this, is that the userform will, in fact, be visible (but not in focus). This means that it may block the part of the document you may want.

Here is what I do with similar situations. At the end of a commandbutton procedure, when I want to keep the userform visible, but NOT in focus, and NOT in the way:

1. I resize (shrink) the userform to have just a wee bit of the userform showing below the title bar.

2. I move the .Top and .Left properties to place the (shrunken) userform at the top of screen. I normally place it to the right of Help on the main toolbar. There is empty space there. Not on the toolbar mind you, I am simply placing its location there, where there is nothing (normally) it can block.

3. I use Application.Activate to move focus back to the document.

So now focus IS back to the document, the userform IS visible, but shrunken to just the title bar and a few pixels of the userform.

I have Userform_Click, (and Userform_DblClick) check its .Top and .Left properties. If they are the shrunken/top placement values, then its resizes back to its original size, and original location.

That way, after the commandbutton actions, the userform gets itself out of the way, focus is returned to the document, but I can get the userform back with a single click.

Oh, I normally do this with a specific "Shrink" commandbutton, but as I state, you could just as easily do it at the end of your commandbutton actions.

Gerry
My paintings and sculpture
 
Good advice. I will try that. I like the change in size of the forms as well

thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top