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

Defining a Userform Owner - Word StartupPosition

Status
Not open for further replies.

Cort

MIS
Apr 16, 2002
154
US
Word 97.

Is a Userform properties one of the fields is StartupPosition. This controls where the form appears on the page. The valid options are Manual, CenterOwner, CenterScreen and Default.

CenterOwner centers the form on the 'owner' of the form. It appears that the default owner is Word as it always appears dead center in the Word window. I want to redefine the owner to a form field called 'company'.

Any way to do that?

Thanks
 
CenterOwner means the owner of the active Window. If the userform is being called from Word, then, yes, Word is the active window (whether full screen or not) and definitely the owner. In fact, regardless of what you do, if the userform is called from Word, Word is the owner.

Therefore, you can not set the owner to be a formfield.

What exactly is the problem?



Gerry
 
Thanks for responding. I've been doing a lot of searching for this and think that the startupposition setting may not be where I need to be looking so I'll clarify as best I can.

I have a form field with the bookmark 'Company'. When this form field is tabbed into a macro is run. This macro shows a combobox userform. This userform has a list of available companies in it (One of the companies uses an ampersand which cannot be used in a standard combobox which is why I have a created VB combobox). The user then selects a company and that result is then placed in the form field.

What happens is that the combobox appears in the center of the Word window when I want it to appear directly on top of the 'company' form field. Is there a way to anchor a userform to an object in the document?

Here is the code I currently use:

-----
Private Sub UserForm_Initialize()

' ComboBox1.Left = ActiveDocument.FormFields("Company")
' ComboBox1.Top = ActiveDocument.FormFields("Company")
' ComboBox1.Width = ActiveDocument.FormFields("Company")
' ComboBox1.Height = ActiveDocument.FormFields("Company")

ComboBox1.ColumnCount = 1

'Load data into ComboBox

ComboBox1.List() = Array("Company 1", "Company 2", "Company 3", "Company 4", "Company 5", "Company 6", "Company 7", "Company 8", "Company 9", "Company 10")



End Sub

Private Sub Cmdclose_Click()

Unload Me

End Sub
Private Sub ComboBox1_Change()

ActiveDocument.FormFields("Company").Result = ComboBox1.Value
Unload Me
End Sub
 
There is no way to specifically anchor the userform to the formfield. There is a way to specifically place a userform at a X,Y location. That is however, X,Y relative to the screen. But what if the user has Word full screen? Or a window? Or a different size window? Or an even different size window? It would be loacted at a specific location, but your formfield may (or may not) be at that location.

I am struggling to understand why this is important. As the userform will have the focus, and the user will have to make their choice, what is the important of having the userform covering the formfield??

Regarding your code, I am curious as to why you have the formfield result tied to the combobox change event. If they change it a number of times (while the userform is still active) it will change the result each time. Why not let them make what choices they want, and have the final result - the one that actually is placed into the formfield - come from the cmdClose button?

Gerry
 
--
I am struggling to understand why this is important.
--

It's important because of the astethics. It works just fine as is but I was trying to get it exactly how I wanted it to look. Looks like it may not be possible.

--
Regarding your code, I am curious as to why you have the formfield result tied to the combobox change event. If they change it a number of times (while the userform is still active) it will change the result each time. Why not let them make what choices they want, and have the final result - the one that actually is placed into the formfield - come from the cmdClose button?
--

Forgive me as VB is something I know very little of. My main focus is elsewhere. The 'Company' textbox is only supposed to hold a single value (company 1-10) and once the selection is made the user just moves to the next field to fill it out.

Thanks again for your help. My users will have to live with it not being perfect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top