On Entry Macro behaviour with Mouse click (Word 2003)

G

Greg Maxey

I have a simple protected form with Text1 DropDown1 and Text2

If the user leaves Text1 empty I want to return to Text1 if the tabs or
"mouses" to DropDown1 or Text2

This is my code:

Sub OnEntry()
Dim oFFLd As Word.FormFields
Set oFFLd = ActiveDocument.FormFields
If oFFLd("Text1").Result = "" Then
oFFLd("Text1").Range.Fields(1).Result.Select
End If
End Sub

and it is set to run onentry to DropDown1 and Text2

This works as expected using the Tab key and it works if the users
mouse clicks to "Text2". However, if the user mouse clicks to
DropDown1 the user is given access of the field and the code isn't
executed until *after* the user makes a selection.

I don't want the user to be able to change the value of Dropdown1 until
they have entered text in Text1. Can this be done?
 
J

Jean-Guy Marcil

Greg Maxey was telling us:
Greg Maxey nous racontait que :
I have a simple protected form with Text1 DropDown1 and Text2

If the user leaves Text1 empty I want to return to Text1 if the tabs
or "mouses" to DropDown1 or Text2

This is my code:

Sub OnEntry()
Dim oFFLd As Word.FormFields
Set oFFLd = ActiveDocument.FormFields
If oFFLd("Text1").Result = "" Then
oFFLd("Text1").Range.Fields(1).Result.Select
End If
End Sub

and it is set to run onentry to DropDown1 and Text2

This works as expected using the Tab key and it works if the users
mouse clicks to "Text2". However, if the user mouse clicks to
DropDown1 the user is given access of the field and the code isn't
executed until *after* the user makes a selection.

I don't want the user to be able to change the value of Dropdown1
until they have entered text in Text1. Can this be done?

I am not sure if you can prevent that behaviour. My feeling is that the
OnEntry macro is not executed until the cursor is "in" the dropdown, which
it isn't until a choice is made when clicking into it.

I guess you could use a workaround such as:

'_______________________________________
Private strDropValue As String
Private Const myDrop As String = "DropDown1"
'_______________________________________
Sub OnExitText1()

strDropValue = ActiveDocument.FormFields(myDrop).Result

End Sub
'_______________________________________

'_______________________________________
Sub OnEntry()

Dim oFFLd As Word.FormFields

Set oFFLd = ActiveDocument.FormFields
If oFFLd("Text1").Result = "" Then
If Selection.Bookmarks(1).Range.FormFields(1).Name = myDrop Then
oFFLd(myDrop).Result = strDropValue
End If
oFFLd("Text1").Range.Fields(1).Result.Select
End If

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Greg Maxey

JGM,

I think you are right about there being no way around this behaviour.
Your suggestion would work for my simple example, but actually the real
world problems is how to validate Text1 has text when mousing to
DropDown1 from *any* other field. An adaption of your suggestion might
work, but it could be laborious in pratice ;-)

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top