PDA

View Full Version : Word Dropdown Form Field Help!



remster
09-30-2008, 02:41 AM
Hi

I hope somone can help me as I'm going out of my mind trying to figure out what I've done wrong.

I have had to create an assessment form for work using Word and the dropdown form field combo box. On a couple of the questions I have insterted an IF statement. It was all working fine this morning but now when I select one macro with relevant answer the previous answer goes blank (this happens no matter which question I answer first).

I have no idea what I've done. The code is probably a bit of a mess as are the combo boxes to be honest but I'm literally pulling my hair out with this.

I apologise if I'm not making any sense but if somebody could help me out I would be very grateful. : pray2:

TonyJollans
09-30-2008, 06:17 AM
I have no idea what I've done.

Well, I certainly have no idea what you've done.

Show us your code. Give us a fighting chance!

remster
09-30-2008, 09:25 AM
Hi Tony

I'll paste the code at the bottom of this message. There are three other pieces of code the same as this (obviously with the dropdown names different each time) but I dont know if it's the VB code or the fact that I've been lazy with the form field as I was rushing it. Anyway, some hints and tips would be appreciated so I don't make the same mistake again.

Sub CascadeList()
If ActiveDocument.FormFields("DropDown31").DropDown.Value = 0 Then
ActiveDocument.FormFields("Dropdown32").DropDown.ListEntries.Clear
Exit Sub
End If
Select Case ActiveDocument.FormFields("Dropdown31").Result
Case "......."
With ActiveDocument.FormFields("Dropdown32").DropDown.ListEntries
.Clear
.Add "N/A"

End With

Case "Hitting"
With ActiveDocument.FormFields("Dropdown32").DropDown.ListEntries
.Clear
.Add "N/A"

End With
Case "Kicking"
With ActiveDocument.FormFields("Dropdown32").DropDown.ListEntries
.Clear
.Add "N/A"

End With
Case "Weapons"
With ActiveDocument.FormFields("Dropdown32").DropDown.ListEntries
.Clear
.Add "Knives"
.Add "Gun"
.Add "Other object"

End With
Case "Other"
With ActiveDocument.FormFields("Dropdown32").DropDown.ListEntries
.Clear
.Add "N/A"

End With
End Select
End Sub

fumei
09-30-2008, 10:05 AM
Could you clarify "the previous answer goes blank "?

Are you saying there WAS something there, and now it is gone? Also, where is this "answer"? In a formfield?

What does "On a couple of the questions I have insterted an IF statement." mean???? There appears to be an IF statement in the procedure CascadeList...but that is not a "question". It is a Sub.

Some more details please.

remster
09-30-2008, 10:23 AM
Could you clarify "the previous answer goes blank "?

Are you saying there WAS something there, and now it is gone? Also, where is this "answer"? In a formfield?

What does "On a couple of the questions I have insterted an IF statement." mean???? There appears to be an IF statement in the procedure CascadeList...but that is not a "question". It is a Sub.

Some more details please.
Certainly.

The question that is asked on the form is one asking what level of violence is used. If they answer that a weapon has been used (ie select Weapon) then I want the next drop down box to be able to display what kind of weapon, but only if they select weapon and not hitting etc.

There are three categories with the same question. When the weapon question and weapon has been selected from the first section, as soon as you click on the next categories question relating to the level of violence, the dropdown box relating to which weapon in the previous category goes blank.

And yes, the answer is in a form field.

Am I making any sense? :dunno

And just to add, I'm not sure if its the form field or the code thats skew whiff. Hence my frustration.

fumei
09-30-2008, 12:53 PM
OK, so the question is TEXT. They select an answer from a dropdown. Fair enough, but I am still confused.

"The question that is asked on the form is one asking what level of violence is used."

"as soon as you click on the next categories question relating to the level of violence, the dropdown box relating to which weapon in the previous category goes blank."

I am confused because it seems to be the same question, yet it is the "next" category.

So they select (in the first question) weapon, then select type of weapon, then ina different? formfield they select the first question again...or are they going back and RE-selecting from the first formfield?

WHAT is firing the Sub CascadeList?

BTW: it may make it easier if you explicitly named things. DropDown32 is a meaningless name. So let me name things, and reask my question.

DropDown("LevelViolence_1") has....Hitting, Kicking, Weapon.

DropDown("Type")...????


DropDown("LevelViolence_2")...has...?????

IF LevelViolence_1 = weapon, THEN "Type" is Cleared, and "Knife", "Gun", "Other object" listed in "Type".

Correct?

Then when user selects from "next" category - LevelViolence_2 (a different formfield dropdown???) - "Type" is Cleared (becomes "blank").

Correct?

remster
09-30-2008, 02:08 PM
I am confused because it seems to be the same question, yet it is the "next" category.
It is the same question, it's just relating to a different set of people in a different section so to speak.

For example, the first set of text questions and formfield answers relate to staff and the next set relates to family and so on but they are the same questions.


So they select (in the first question) weapon, then select type of weapon, then ina different? formfield they select the first question again...or are they going back and RE-selecting from the first formfield?
The question is about level of violence used and the Dropdown would include 'hitting', 'kicking', 'weapons' and 'other'. If they select 'weapons' the next drop down would allow them to select a weapon used. If they selected anything else the dropdown would show 'N/A'



IF LevelViolence_1 = weapon, THEN "Type" is Cleared, and "Knife", "Gun", "Other object" listed in "Type".

Correct?

Then when user selects from "next" category - LevelViolence_2 (a different formfield dropdown???) - "Type" is Cleared (becomes "blank").

Correct?
Yes, a different formfield dropdown (but as explained above, the same question) ie I'm selecting Dropdown_34 but then Dropdown_32 becomes blank. And then I select Dropdown_36 and Dropdown_34 becomes blank even though they are loading different modules, if that makes sense.

To be honest, I haven't done any coding of any sort since my first year JAVA exam at uni (except maybe some MEL script) so I am a little lost. Especially as they stuck me with this late last night after I had been down the pub. The weird thing is, it seemed to work fine but this morning it went a bit wrong.

I realise there are probably bits of code missing that I need and bits of code that I don't, but like I say I'm a bit lost.

Anyway, your help is very much appreciated. :thumb

TonyJollans
10-01-2008, 08:49 AM
I'm having difficulty following all the references to the different questions and formfields but my guess is that you have a typo - or you have cut and pasted and not changed some code - and you have a reference to the wrong field somewhere - or you are running the wrong macro on exit from one or more fields. As Gerry says, give them proper names instead of the default generic ones and it will be easier to spot errors.

Also single step through the code and make sure what you think is running is actually running and doing what it should. It's very hard to debug remotely like this, it's much easier when you have all the information in front of you.

fumei
10-02-2008, 08:53 AM
And please answer the question as to when code is supposed to be executed. I am assuming it is an OnExit macro.

If I understand you correctly, yes this is quite possible. However, you MUST write out clearly and precisely exactly what the logic is. As I mentioned, and Tony reiterated, doing so is easier if you use names that are meaningful.

"It is the same question, it's just relating to a different set of people in a different section so to speak.

For example, the first set of text questions and formfield answers relate to staff and the next set relates to family and so on but they are the same questions."

Also, try and stop thinking - I know this sounds weird - like a human being. Word is a computer application. It does NOT know anything about "same", i.e. same question.

To you, they are the "same" question. But to Word, they are not questions at all. It is text, just text.

"And then I select Dropdown_36 and Dropdown_34 becomes blank even though they are loading different modules, if that makes sense."

No, sorry, but it does not. Modules? Let me try, using names.

"first question" - user selects from dropdown "Q1"
ummm, result of that choice (I think your Dropdown_34) - hey, let us call it "Result".

"Next" question - your Dropdown_36 - let's call it "Q2".

So - and again, I strongly encourage you to actually WRITE out the logic - let's see if we can get something. The coding part of doing this kind of stuff is not hard. The hard part is being precisely explicit in the logic.

Q1 (dropdown) has: Hitting, Kicking, Weapon.

As the OnExit macro for Q1:
Select Case ActiveDocument.FormFields("Q1").Result
Case "......."
With ActiveDocument.FormFields("Result").DropDown.ListEntries
.Clear
.Add "N/A"
End With
Case "Hitting"
With ActiveDocument.FormFields("Result").DropDown.ListEntries
.Clear
.Add "N/A"
End With
Case "Kicking"
With ActiveDocument.FormFields("Result").DropDown.ListEntries
.Clear
.Add "N/A"
End With
Case "Weapons"
With ActiveDocument.FormFields("Result").DropDown.ListEntries
.Clear
.Add "Knives"
.Add "Gun"
.Add "Other object"
End With
Case "Other"
With ActiveDocument.FormFields("Result").DropDown.ListEntries
.Clear
.Add "N/A"
End With
End Select


OK, this adjusts your Dropdown_32 (my "Result") to reflect user selection of "Q1" (your Dropdown_31). That is, if "Weapon" is selected in Q1, then Result is cleared and "knives", "Gun", "Other" is listed in Result.

OK, now, it seems that no matter what is in Result, when the user enters Q2 - the "next" question, you want "Result" (Dropdown_32) cleared.

Fine. Not a problem. Use an OnEntry macro for it.

ActiveDocument.Formfields("Result").DropDown _
.ListEntries.Clear

Voila. It is cleared.

Now, you are also saying that the next question after THAT - your Dropdown_36 - ALSO makes "Result" (Dropdown_32) blank....except....you say Dropdown_34 becomes blank.

Which reiterates Tony's comment, and mine. Give meaningful names. It makes it much easier to figure out the logic. I will repeat that the coding of this kind of stuff is not hard. In fact, it is EASY. The hard part is figuring out rock solid logic.

I suspect though, that there may be design improvements possible. However, as I remain unclear as to the logic, I can not really offer any suggestions.

Is it possible to attach a sample document, even an shorter one?