PDA

View Full Version : Make conditional drop down fields modular



itsac
01-05-2006, 07:34 AM
Good morning,

I'm using the wonderful code for a conditional drop down field submitted by fumei (thank you very much) and I'm trying to use the same 2 drop down fields, three more times on my document. I have not been able to wrap my brain around the logic of making this repeat itself on the next appropriate bookmark.

Any help?

Thanks. Amy: pray2:

fumei
01-05-2006, 07:30 PM
Hi Amy! Welcome to VBAX. Could you elaborate? I am not clear. You want to use the same logic again from the same dropdown? Or do you want to use the same logic for a different dropdown?

If you can post a file, that would be great. You must make the doc file a ZIP file to post here.

itsac
01-06-2006, 06:34 AM
Sorry, I don't know enough to make my question clear enough. I've attached my document.

In my document I have:

Dropdown1 and Result1
Dropdown2 and Result2
Dropdown3 and Result3
Dropdown4 and Result4

And I want to use the same code for each, so I was wondering how I could just get it to loop through the numbers or either loop through to the next field.

Thanks for taking the time to help.

Amy: pray2:

fumei
01-06-2006, 07:58 AM
Here you go. This is what I did.

1. Part of the problem is that the code is actioning on a formfield named Result. You do not HAVE such a formfield. You have Result1, Result2, Result3....

2. However, this is good because the numbering matches to the dropdown names - Dropdown1, Dropdown2.....

3. I made a string variable (FormfieldNumber) that picks up the LAST character of the CURRENT dropdown. So if you are at Dropdown3, it picks up "3". It then actions the conditional code and places the result in Result & FormfieldNumber - or, "Result3".

This allows the conditional code to action on the current dropdown. Of course you should (and do) have this only firing on the dropdowns that cause the conditions. So you are cool.

BTW: You will notice that instead of:
ActiveDocument.Formfields("Dropdown1")
it now is:
oFF("Dropdown1")
This is because I made the document itself an object, then used that to make an object of the formfield collection (oFF). It just makes the code a little shorter. You can reference the formfields with just oFF - instead of ActiveDocument.Formfields.

Hope this is what you were looking for.

fumei
01-06-2006, 08:04 AM
Just read the above...uh, maybe that was not so clear. I will try again.

You want to know how to go through multiple formfields, using the same conditional logic. If it was different logic then you would - of course - have to use a different procedure.

OK, the issue then is identification of which formfield you want to get the resulting list items. Fortunately you DO have matching numbers from the originating formfield and the resulting formfields. That is:

Dropdown1 - goes to Result1
Dropdown2 - goes to Result2
Dropdown3 - goes to Result3
Dropdown4 - goes to Result4

Ah...so grab the LAST character of the dropdown you are working with...be it 1, 2, 3, or 4. and append that on to "Result", to get Result1, Result2..etc etc.

Now you have the correct Resultx formfield to put your condtional list into.

Hope that makes sense!

itsac
01-06-2006, 08:13 AM
That's what I was looking for, thank you, thank you!

I'll take a look at the code and try to wrap my brain around the concept.

Thanks. Amy

fumei
01-06-2006, 08:16 AM
You are welcome. Always nice to see someone using my code.

As an aside, you may want to increase the space between Dropdown(x) and Result(x). They look kind of mushed together.