Form Executed from userform, is behind document1, why? 
Author Message
 Form Executed from userform, is behind document1, why?

Folks, I've had some great help in getting a userform loaded up with
many option buttons, everything works fine except after I select the
form that I want to see, it is found behind document1 or whatever and
I have to minimize the document to see the form... In other words it
is not the active document...why is this happening, I'm using
word2000..I have alot of forms that will be executed from the userform
and hope to correct whatever is wrong..  btw, I load up the userform
from a button on the toolbar, Thanks  Bill


Tue, 16 Sep 2003 13:34:51 GMT  
 Form Executed from userform, is behind document1, why?
Give us a few more clues

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

Quote:
> Folks, I've had some great help in getting a userform loaded up with
> many option buttons, everything works fine except after I select the
> form that I want to see, it is found behind document1 or whatever and
> I have to minimize the document to see the form... In other words it
> is not the active document...why is this happening, I'm using
> word2000..I have alot of forms that will be executed from the userform
> and hope to correct whatever is wrong..  btw, I load up the userform
> from a button on the toolbar, Thanks  Bill



Tue, 16 Sep 2003 18:55:58 GMT  
 Form Executed from userform, is behind document1, why?

For some reason when I load up a document from the userform, it will not be the
active  document but will go behind  document1..I took my userform and macro to
work and it does the same thing.. I can get the form to open like it should
only if I close down document1. Generally when you open up a new document it is
the active document and it is in front....Right?  Bill

Quote:

> Give us a few more clues

> Please post any follow-up or new questions to the Newsgroups so that others
> may benefit therefrom or contribute thereto.

> Hope this helps,
> Doug Robbins - Word MVP


> > Folks, I've had some great help in getting a userform loaded up with
> > many option buttons, everything works fine except after I select the
> > form that I want to see, it is found behind document1 or whatever and
> > I have to minimize the document to see the form... In other words it
> > is not the active document...why is this happening, I'm using
> > word2000..I have alot of forms that will be executed from the userform
> > and hope to correct whatever is wrong..  btw, I load up the userform
> > from a button on the toolbar, Thanks  Bill



Wed, 17 Sep 2003 08:53:51 GMT  
 Form Executed from userform, is behind document1, why?
Hi Bill,

How are you calling the UserForm and what is the code in your macro doing.

How about copying the code from your macro and from the userform into a post
and then we really might be able to see what you are doing.

I am sorry, but your explanation doesn't leave me any the wiser.

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

For some reason when I load up a document from the userform, it will not be
the active  document but will go behind  document1..I took my userform and
macro to work and it does the same thing.. I can get the form to open like
it should only if I close down document1. Generally when you open up a new
document it is the active document and it is in front....Right?  Bill
Give us a few more clues
Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.
Hope this helps,
Doug Robbins - Word MVP

Quote:
> Folks, I've had some great help in getting a userform loaded up with
> many option buttons, everything works fine except after I select the
> form that I want to see, it is found behind document1 or whatever and
> I have to minimize the document to see the form... In other words it
> is not the active document...why is this happening, I'm using
> word2000..I have alot of forms that will be executed from the userform
> and hope to correct whatever is wrong..  btw, I load up the userform
> from a button on the toolbar, Thanks  Bill



Wed, 17 Sep 2003 09:58:34 GMT  
 Form Executed from userform, is behind document1, why?
Hey Doug, I can help clarify because I helped him a little.  He has an
add-in template in the Startup folder with a toolbar button to open up
UserForm1.  Code:

Sub OpenUserForm()
    Load UserForm1
    UserForm1.Show
End Sub

He then has a set of option buttons whereby he clicks on one and then clicks
a command button to open up a document based on the template for the option
button he chose.  Code:

Private Sub CommandButton1_Click()
Dim ocheck As MSForms.Control
Dim x As Long
For x = 1 To 20
    Set ocheck = Me.Controls("optionbutton" & x)
    If ocheck.Value = True Then
        Documents.Add Template:= _
            "C:\my documents\fire\forms\" & ocheck.Caption,
Newtemplate:=False
    End If
Next x
Unload UserForm1

End Sub

Works for me in Word 97, but causes his problem described in Word 2000.  I
mentioned to Bill to add the UserForm and code to normal.dot as an option,
but then there is the problem of changing user's global, as well as
understanding how to get them to add the module and form to each normal.dot.

Thanks for the assistance.  I'm stumped as to why this happens in Word 2000.
At first I thought it was the way it handled code as an add-in, but the
add-in (Startup folder) works for me in Word 97.

Bill Foley
www.pttinc.com

Quote:
> Hi Bill,

> How are you calling the UserForm and what is the code in your macro doing.

> How about copying the code from your macro and from the userform into a
post
> and then we really might be able to see what you are doing.

> I am sorry, but your explanation doesn't leave me any the wiser.

> Please post any follow-up or new questions to the Newsgroups so that
others
> may benefit therefrom or contribute thereto.

> Hope this helps,
> Doug Robbins - Word MVP


> For some reason when I load up a document from the userform, it will not
be
> the active  document but will go behind  document1..I took my userform and
> macro to work and it does the same thing.. I can get the form to open like
> it should only if I close down document1. Generally when you open up a new
> document it is the active document and it is in front....Right?  Bill

> Give us a few more clues
> Please post any follow-up or new questions to the Newsgroups so that
others
> may benefit therefrom or contribute thereto.
> Hope this helps,
> Doug Robbins - Word MVP


> > Folks, I've had some great help in getting a userform loaded up with
> > many option buttons, everything works fine except after I select the
> > form that I want to see, it is found behind document1 or whatever and
> > I have to minimize the document to see the form... In other words it
> > is not the active document...why is this happening, I'm using
> > word2000..I have alot of forms that will be executed from the userform
> > and hope to correct whatever is wrong..  btw, I load up the userform
> > from a button on the toolbar, Thanks  Bill



Wed, 17 Sep 2003 14:44:06 GMT  
 Form Executed from userform, is behind document1, why?
Thanks Bill,  you explained it correctly...Bill
Quote:

> Hey Doug, I can help clarify because I helped him a little.  He has an
> add-in template in the Startup folder with a toolbar button to open up
> UserForm1.  Code:

> Sub OpenUserForm()
>     Load UserForm1
>     UserForm1.Show
> End Sub

> He then has a set of option buttons whereby he clicks on one and then clicks
> a command button to open up a document based on the template for the option
> button he chose.  Code:

> Private Sub CommandButton1_Click()
> Dim ocheck As MSForms.Control
> Dim x As Long
> For x = 1 To 20
>     Set ocheck = Me.Controls("optionbutton" & x)
>     If ocheck.Value = True Then
>         Documents.Add Template:= _
>             "C:\my documents\fire\forms\" & ocheck.Caption,
> Newtemplate:=False
>     End If
> Next x
> Unload UserForm1

> End Sub

> Works for me in Word 97, but causes his problem described in Word 2000.  I
> mentioned to Bill to add the UserForm and code to normal.dot as an option,
> but then there is the problem of changing user's global, as well as
> understanding how to get them to add the module and form to each normal.dot.

> Thanks for the assistance.  I'm stumped as to why this happens in Word 2000.
> At first I thought it was the way it handled code as an add-in, but the
> add-in (Startup folder) works for me in Word 97.

> Bill Foley
> www.pttinc.com


> > Hi Bill,

> > How are you calling the UserForm and what is the code in your macro doing.

> > How about copying the code from your macro and from the userform into a
> post
> > and then we really might be able to see what you are doing.

> > I am sorry, but your explanation doesn't leave me any the wiser.

> > Please post any follow-up or new questions to the Newsgroups so that
> others
> > may benefit therefrom or contribute thereto.

> > Hope this helps,
> > Doug Robbins - Word MVP


> > For some reason when I load up a document from the userform, it will not
> be
> > the active  document but will go behind  document1..I took my userform and
> > macro to work and it does the same thing.. I can get the form to open like
> > it should only if I close down document1. Generally when you open up a new
> > document it is the active document and it is in front....Right?  Bill

> > Give us a few more clues
> > Please post any follow-up or new questions to the Newsgroups so that
> others
> > may benefit therefrom or contribute thereto.
> > Hope this helps,
> > Doug Robbins - Word MVP


> > > Folks, I've had some great help in getting a userform loaded up with
> > > many option buttons, everything works fine except after I select the
> > > form that I want to see, it is found behind document1 or whatever and
> > > I have to minimize the document to see the form... In other words it
> > > is not the active document...why is this happening, I'm using
> > > word2000..I have alot of forms that will be executed from the userform
> > > and hope to correct whatever is wrong..  btw, I load up the userform
> > > from a button on the toolbar, Thanks  Bill



Wed, 17 Sep 2003 14:27:50 GMT  
 Form Executed from userform, is behind document1, why?
I just went to another computer with word97, and it works fine.....Bill
Quote:

> Thanks Bill,  you explained it correctly...Bill


> > Hey Doug, I can help clarify because I helped him a little.  He has an
> > add-in template in the Startup folder with a toolbar button to open up
> > UserForm1.  Code:

> > Sub OpenUserForm()
> >     Load UserForm1
> >     UserForm1.Show
> > End Sub

> > He then has a set of option buttons whereby he clicks on one and then clicks
> > a command button to open up a document based on the template for the option
> > button he chose.  Code:

> > Private Sub CommandButton1_Click()
> > Dim ocheck As MSForms.Control
> > Dim x As Long
> > For x = 1 To 20
> >     Set ocheck = Me.Controls("optionbutton" & x)
> >     If ocheck.Value = True Then
> >         Documents.Add Template:= _
> >             "C:\my documents\fire\forms\" & ocheck.Caption,
> > Newtemplate:=False
> >     End If
> > Next x
> > Unload UserForm1

> > End Sub

> > Works for me in Word 97, but causes his problem described in Word 2000.  I
> > mentioned to Bill to add the UserForm and code to normal.dot as an option,
> > but then there is the problem of changing user's global, as well as
> > understanding how to get them to add the module and form to each normal.dot.

> > Thanks for the assistance.  I'm stumped as to why this happens in Word 2000.
> > At first I thought it was the way it handled code as an add-in, but the
> > add-in (Startup folder) works for me in Word 97.

> > Bill Foley
> > www.pttinc.com


> > > Hi Bill,

> > > How are you calling the UserForm and what is the code in your macro doing.

> > > How about copying the code from your macro and from the userform into a
> > post
> > > and then we really might be able to see what you are doing.

> > > I am sorry, but your explanation doesn't leave me any the wiser.

> > > Please post any follow-up or new questions to the Newsgroups so that
> > others
> > > may benefit therefrom or contribute thereto.

> > > Hope this helps,
> > > Doug Robbins - Word MVP


> > > For some reason when I load up a document from the userform, it will not
> > be
> > > the active  document but will go behind  document1..I took my userform and
> > > macro to work and it does the same thing.. I can get the form to open like
> > > it should only if I close down document1. Generally when you open up a new
> > > document it is the active document and it is in front....Right?  Bill

> > > Give us a few more clues
> > > Please post any follow-up or new questions to the Newsgroups so that
> > others
> > > may benefit therefrom or contribute thereto.
> > > Hope this helps,
> > > Doug Robbins - Word MVP


> > > > Folks, I've had some great help in getting a userform loaded up with
> > > > many option buttons, everything works fine except after I select the
> > > > form that I want to see, it is found behind document1 or whatever and
> > > > I have to minimize the document to see the form... In other words it
> > > > is not the active document...why is this happening, I'm using
> > > > word2000..I have alot of forms that will be executed from the userform
> > > > and hope to correct whatever is wrong..  btw, I load up the userform
> > > > from a button on the toolbar, Thanks  Bill



Wed, 17 Sep 2003 14:51:31 GMT  
 Form Executed from userform, is behind document1, why?
Hi Bill and Bill,

Here is a post from fellow MVP Jonathon West in the Word97VBA newsgroup that
I think is dealing with the same problem that you have.  Note Jonathon's
caution about not running the code under Word 97

Quote

Hi Jasper,

Here is a copy of a message I sent in response to a similar question about a
year ago.

Create a UserForm (for the purposes of the example, call it UserForm1. Place
a CommandButton on it (called CommandButton1)

Place the following code into the UserForm

Option Explicit
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function SetParent Lib "user32" _
      (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Sub CommandButton1_Click()
    Dim iHandleForm As Long
    Dim iHandleDoc As Long
    Dim iNull As Long
    Dim oDoc As Document

    iHandleForm = GetActiveWindow()
    Set oDoc = Documents.Add
    iHandleDoc = GetActiveWindow()
    iNull = SetParent(iHandleForm, iHandleDoc)
    oDoc.Activate
End Sub

Call the UserForm by means of the following routine, placed in a module

Sub TestFormFocus()
    UserForm1.Show vbModeless
End Sub

With your first document open, if you run the macro, what should happen is
the following

1. The UserForm will appear. Click on the CommandButton
2. A new document will be created, and the form will appear above the new
document. You will be able to type into the new document with the form
visible.
3. You can Alt-Tab back to the first document, and the form will be hidden
under it.
3. Alt-tab back to the second document, and click the CommandButton again. A
further document will get created.

The key to this are the Windows API calls GetActiveWindow and SetParent. It
is *absolutely vital* that these calls are made when the application is in
the correct state.

The GetActiveWindow call that places a value into iHandleForm must be called
when the UserForm is the active window. For code used in a larger
application, I would recommend that you make iHandleWindow a module-level
variable, and do the GetActiveWindow call as the first thing in the Activate
event of the form. It only needs to be called once, the value of the handle
will not change until the form is unloaded.

The second GetActiveWindow call must be made when the new document is
active. Again, once you have made the call you can store the value of the
handle, it will not change while that window is open.

The exact timing of the SetParent call is less vital, provided you are quite
certain you have valid values for iHandleForm and iHandleDoc

Things would be a lot easier if the hWnd property of Word's various windows
were made available to VBA <sigh>

Don't allow this code to run under Word 97, it will freeze the machine.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:
> Hi,

> I' ve got a problem I can't solve.
> It has to do with the difference between Word97'sMDI and Word2000/XP's
SDI.

> I've got a userform in witch a user selects a new documenttype to create.
> The document is then added with a Documents.add statement. The userform
> stays open but changes it's looks to enable the user to input some
> standard document data. When the data is inserted, the userform writes the
> data to the created document and closes.
> In Word97 this works fine. In Word2000 however, the document is added in a
> new single takbar window. (This MDI/SDI has been discussed widely before)

> The problem occurs when the added document is activated (by Word) : For
the
> userform is a child window of the original document interface the macro
was
> called from, it does not display in this new window! The solution I'm
> searching for would be to transfer the "parenthood" of my userform to this
> new document interface. I've tried to do this with a SetParent API call,
but
> this did not work completely(all windows were disabled from user input at
> the end)

> I've also searched the Internet on this issue completely, but found no
> answers. (the only article I think suits this a little, is Romke Soldaat's
> article on OfficeVBA.com. Sadly I discovered this service is now "For
> members only", so I cant read it.)

> Anybody into this?

> Jasper Mandos.

Unquote

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

- Show quoted text -

Quote:
> I just went to another computer with word97, and it works fine.....Bill


> > Thanks Bill,  you explained it correctly...Bill


> > > Hey Doug, I can help clarify because I helped him a little.  He has an
> > > add-in template in the Startup folder with a toolbar button to open up
> > > UserForm1.  Code:

> > > Sub OpenUserForm()
> > >     Load UserForm1
> > >     UserForm1.Show
> > > End Sub

> > > He then has a set of option buttons whereby he clicks on one and then
clicks
> > > a command button to open up a document based on the template for the
option
> > > button he chose.  Code:

> > > Private Sub CommandButton1_Click()
> > > Dim ocheck As MSForms.Control
> > > Dim x As Long
> > > For x = 1 To 20
> > >     Set ocheck = Me.Controls("optionbutton" & x)
> > >     If ocheck.Value = True Then
> > >         Documents.Add Template:= _
> > >             "C:\my documents\fire\forms\" & ocheck.Caption,
> > > Newtemplate:=False
> > >     End If
> > > Next x
> > > Unload UserForm1

> > > End Sub

> > > Works for me in Word 97, but causes his problem described in Word
2000.  I
> > > mentioned to Bill to add the UserForm and code to normal.dot as an
option,
> > > but then there is the problem of changing user's global, as well as
> > > understanding how to get them to add the module and form to each
normal.dot.

> > > Thanks for the assistance.  I'm stumped as to why this happens in Word
2000.
> > > At first I thought it was the way it handled code as an add-in, but
the
> > > add-in (Startup folder) works for me in Word 97.

> > > Bill Foley
> > > www.pttinc.com


> > > > Hi Bill,

> > > > How are you calling the UserForm and what is the code in your macro
doing.

> > > > How about copying the code from your macro and from the userform
into a
> > > post
> > > > and then we really might be able to see what you are doing.

> > > > I am sorry, but your explanation doesn't leave me any the wiser.

> > > > Please post any follow-up or new questions to the Newsgroups so that
> > > others
> > > > may benefit therefrom or contribute thereto.

> > > > Hope this helps,
> > > > Doug Robbins - Word MVP


> > > > For some reason when I load up a document from the userform, it will
not
> > > be
> > > > the active  document but will go behind  document1..I took my
userform and
> > > > macro to work and it does the same thing.. I can get the form to
open like
> > > > it should only if I close down document1. Generally when you open up
a new
> > > > document it is the active document and it is in front....Right?
Bill

> > > > Give us a few more clues
> > > > Please post any follow-up or new questions to the Newsgroups so that
> > > others
> > > > may benefit therefrom or contribute thereto.
> > > > Hope this helps,
> > > > Doug Robbins - Word MVP


> > > > > Folks, I've had some great help in getting a userform loaded up
with
> > > > > many option buttons, everything works fine except after I select
the
> > > > > form that I want to see, it is found behind document1 or whatever
and
> > > > > I have to minimize the document to see the form... In other words
it
> > > > > is not the active document...why is this happening, I'm using
> > > > > word2000..I have alot of forms that will be executed from the
userform
> > > > > and hope to correct whatever is wrong..  btw, I load up the
userform
> > > > > from a button on the toolbar, Thanks  Bill



Thu, 18 Sep 2003 19:45:06 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Why does form2 hide behind form 1

2. Why does my form drop behind ?

3. Am I too far behind?

4. How to center a Form to the UserForm it belongs to, if the UserForm has moved

5. Executing a module behind a control

6. Why does DBGrid Refresh lag behind recordset

7. Showing another form behind active form...

8. MDI Form problem- Child Forms hidden behind picture.

9. Am I using UserForm Right?

10. Where am I in the Userform?

11. Runtime Compile Errors in executing Userform in Citrix

12. Change UserForm look while executing

 

 
Powered by phpBB® Forum Software