PDA

View Full Version : UserForm on Top



jbfrank3
07-10-2007, 05:11 AM
I have a very simple UserForm in Word with a couple of text boxes and combo boxes...nothing extravagant.

The problem is that as soon as 1 letter is typed into the first TextBox, the form is no longer selected. It's still visible, but the Word Document is the active document.

How do I resolve this?

Thank you in advance for your help.

Currently using MS Word 2003 SP3

mvidas
07-10-2007, 05:13 AM
jbfrank3,

Can you post a sample file containing the userform? Or if not, just the code behind it? What you're describing isn't usual, so we'd have to see how it is working to be able to tell you why its doing it.

jbfrank3
07-10-2007, 05:19 AM
Module1 contains the following:
Sub ShowComboBox()
UserForm.Show
End Sub


Each field on the UserForm contains code similar to the following:

Private Sub TextBox1_Change()
ActiveDocument.FormFields("Text1").Result = TextBox1.Value

End Sub

I have a separate "Private Sub" for each field.

mvidas
07-10-2007, 05:32 AM
Hmm, I'm not getting the same functionality... You might want to try using the _AfterUpdate event of the textbox instead of the _change ? The only time I know of that the form will instantly update while typing like this is if you have the ShowModal property of the form set to False, but it still shouldn't steal focus. You don't happen to call the .Show method again of the userform within your _Change events are you?

It could be a versional difference too I suppose, I'm using word 2000

mdmackillop
07-10-2007, 01:24 PM
Hi JB,
Welcome to VBAX.

The Change event is triggered by each letter entered.
Try
Private Sub TextBox1_AfterUpdate()
ActiveDocument.FormFields("Text1").Result = TextBox1.Value
End Sub

fumei
07-10-2007, 04:07 PM
Yes, yes. The _Change event fires for EVERY change...as it should, since it is a change event.

If you type "hello":

h - _Change fires.
e - _Change fires.
l - _Change fires.
l - _Change fires.
o - _Change fires.

This is very inefficient. Why are you doing this? Plus, using _Change like that allows no error trapping. What if they type in "zxvMNFSJVS"? Is that an acceptable input? Perhaps.

However, here is the rub. It seems like (as Matt suggests) you must have other code you are not mentioning.

If the userform is modal - there is no update to the formfield until the userform loses focus.

If the userform is NOT modal - there is update. However, the userform should still show as the active focus.

What you describe is NOT normal behaviour.