PDA

View Full Version : Form-Fields causing crash?



SilverSN95
03-15-2011, 12:59 PM
Hey,

I'm having an issue with a Word form-field dropdown that may or may not be VBA related, but I'm hoping someone might know what is going on.

KECoverage_Exit() is called from a form-field dropodown, "KECoverage" on Exit. This macro then changes the value of two other dropdowns.

These other dropdowns also normally update a text field when changed, so the "Call Thing3(/4)_Exit" calls update those fields for the dropdown values that were changed.

All of this works the way I would like, EXECPT for the fact that Word crashes every so often when the user is changing the dropdown value. It seemed like clicking/tabbing more quickly than normal caused the problem, but occasionally just going through slowly would cause the error. Other times I can't even reproduce the error.

I guess what I'm asking is, does this sound like an error with the macro/form field combination, or is this just an error with Word?

Thanks.


Public Sub Thing3_Exit()
With ActiveDocument.FormFields.Item("Thing3")
If .DropDown.Value = 1 Then
ActiveDocument.FormFields.Item("Thing3W").Result = " blahblahblah "
ElseIf .DropDown.Value = 2 Then
ActiveDocument.FormFields.Item("Thing3W").Result = " blahblahblah "
Else
ActiveDocument.FormFields.Item("Thing3W").Result = " "
End If
End With
End Sub


Public Sub Thing4_Exit()
With ActiveDocument.FormFields.Item("Thing4")
If .DropDown.Value = 1 Then
ActiveDocument.FormFields.Item("Thing4W").Result = "blahblahblah"
ElseIf .DropDown.Value = 2 Then
ActiveDocument.FormFields.Item("Thing4W").Result = " blahblahblah"
Else
ActiveDocument.FormFields.Item("Thing4W").Result = " "
End If
End With
End Sub


Public Sub KECoverage_Exit()

With ActiveDocument.FormFields.Item("KECoverage")

If .Result = " blahblahblah 2" Then
ActiveDocument.FormFields.Item("Thing3").DropDown.Value = 2
ActiveDocument.FormFields.Item("Thing4").DropDown.Value = 2
Call Thing3_Exit
Call Thing4_Exit
ElseIf .Result = " blahblahblah 1" Then
ActiveDocument.FormFields.Item("Thing3").DropDown.Value = 1
ActiveDocument.FormFields.Item("Thing4").DropDown.Value = 1
Call Thing3_Exit
Call Thing4_Exit
Else
ActiveDocument.FormFields.Item("Thing3").DropDown.Value = 3
ActiveDocument.FormFields.Item("Thing4").DropDown.Value = 3
Call Thing3_Exit
Call Thing4_Exit
End If

End With

End Sub

fumei
03-15-2011, 01:18 PM
OK, if KECoverage_Exit fires, here is what happens (using blahblahblah 2 as the example):

ActiveDocument.FormFields.Item("Thing3").DropDown.Value = 2
ActiveDocument.FormFields.Item("Thing4").DropDown.Value = 2
Call the Exit procedure for Thing3 (even though you are not actually exiting Thing3), which does:
ActiveDocument.FormFields.Item("Thing3W").Result = " blahblahblah "
Call the Exit procedure for Thing4 (even though you are not actually exiting Thing4), which does:
ActiveDocument.FormFields.Item("Thing4W").Result = " blahblahblah"

The logic values of the Exit procedures can simply be included, with no need (at least under this circumstance) to do the Calls. I suspect that is the issue.

Public Sub KECoverage_Exit()
Dim DocFF As FormFields
Set DocFF = ActiveDocument.FormFields

Select Case DocFF("KECoverage").Result
Case " blahblahblah 2"
DocFF("Thing3").DropDown.Value = 2
DocFF("Thing4").DropDown.Value = 2
DocFF("Thing3W").Result = " blahblahblah "
DocFF("Thing4W").Result = " blahblahblah"
Case " blahblahblah 1"
DocFF("Thing3").DropDown.Value = 1
DocFF("Thing4").DropDown.Value = 1
DocFF("Thing3W").Result = " blahblahblah "
DocFF("Thing4W").Result = " blahblahblah"
Case Else
DocFF("Thing3").DropDown.Value = 3
DocFF("Thing4").DropDown.Value = 3
DocFF("Thing3W").Result = " "
DocFF("Thing4W").Result = " "
End Select
End Sub
Using an object (DocFF) for the formfields. I do not like typing more than I have to, plus using obejcts is a good habit.

SilverSN95
03-22-2011, 09:35 AM
Thanks Fumei, that is a much better way of doing it, and I have changed the other functions to use an object reference as well. However I am still running into the issue but I have figured out how to produce it.

It seems that if I click on any of the dropdowns I have a macro set to run on exit, and then click into another field without first selecting an item, Word crashes. I notice that Word does not let you tab out of the dropdown without selection an item (only click), and doing this from a dropdown without an "exit" macro does not cause a problem.

Is there something going on with my exit macros (stepping through debugger didnt bring up any errors) or could this just be a Word bug?

Thanks.