PDA

View Full Version : Add a chosen value to the document



Giwdeh
03-28-2012, 04:35 AM
I have two dropdownlist , ArbOmr and SSYK. This macro:


Sub CascadeList()
If ActiveDocument.FormFields("ArbOmr").DropDown.Value = 0 Then
ActiveDocument.FormFields("SSYK").DropDown.ListEntries.Clear
Exit Sub
End If
Select Case ActiveDocument.FormFields("ArbOmr").Result
Case "10"
With ActiveDocument.FormFields("SSYK").DropDown.ListEntries
.Clear
.Add "0"
.Add "4"
.Add "X"
End With
End Select
End Sub

It works very well, it is possible to choose the correct number in SSYK.

But - something missing. I want my choice to 'stay' in the document when I print it. :dunno

Which is the solution ?

Thanks for any idea.

Giwdeh

fumei
03-28-2012, 10:59 AM
1. Please the VBA code tags when posting code.

2. Why use Select Case when you only have one Case? It is also a good practice to use a Case Else.

3. What is supposed to "stay"? The logic of the code is:

IF Arbomr value = 0, clear all entries in SSYK and Exit (nothing else happens).

IF Arbomr is NOT 0, the code continues, SSYK is cleared and 0, 4, X are added.

What "choice" are you talking about?

Giwdeh
03-28-2012, 10:33 PM
1. Please the VBA code tags when posting code.

Sorry, new here and didn't know how-to

2. Why use Select Case when you only have one Case? It is also a good practice to use a Case Else.

I have 16 cases, but they are similar.


3. What is supposed to "stay"? The logic of the code is:

IF Arbomr value = 0, clear all entries in SSYK and Exit (nothing else happens).

IF Arbomr is NOT 0, the code continues, SSYK is cleared and 0, 4, X are added.

What "choice" are you talking about?

I have a form, the first step is to choose one of 16 values in the ArbOmr and this will be written it in field 1. And the result your choice give you the next list SSYK. And my problem is that this result is written in field two, but when I print this document is the field empty.
I have realized that the problem is not in the code, I have to disable update fields when I print the document.

Giwdeh

fumei
03-29-2012, 02:09 AM
Field 1??? What field 1? Please post your entire code. If there are 16 cases, there should be, well, 16 Cases. As long as they are not equal then this is what Case is for.

Does SSYK start out empty?

choose one of 16 values in the ArbOmr and this will be written it in field 1But this is not what happens, or so it seems. Please post your entire code.

macropod
03-29-2012, 05:05 AM
Hi Giwdeh,

Since you have a DropDown named 'ArbOmr' and it appears there's a 1:1 correspondence between the value chosen there and the 'SSYK' value, you can dispense with both the macro code and the 'SSYK' DropDown. All you need to do is to set the 'ArbOmr' DropDown's 'calculate on exit' property and insert a series of formula fields, coded along the lines of:
{IF{REF ArbOmr}= "some value" "output string"}
with one such field for each possible 'ArbOmr' DropDown choice.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message.