Macro on exiting text box

S

SGT Buckeye

Can someone look at this code and tell me why it won't work? What I
want to do is create a dropdown list in the Form Field called
"Deduction1" if anything is typed into the Form Field called "CLS1".

Sub CascadeList()
If ActiveDocument.FormFields("CLS1").TextBox.Value = 0 Then

ActiveDocument.FormFields("Deduction1").DropDown.ListEntries.Clear
Exit Sub
End If
Select Case ActiveDocument.FormFields("CLS1").Result
Case "*"
With
ActiveDocument.FormFields("Deduction1").DropDown.ListEntries
.Clear
.Add "A1"
.Add "A2"
.Add "A3"
.Add "A4"
.Add "A5"
.Add "A6"
.Add "A7"
.Add "A8"
.Add "A9"
.Add "B1"
.Add "B2"
.Add "B3"
.Add "B4"
.Add "B5"
.Add "B6"
.Add "B7"
.Add "B8"
.Add "C1"
.Add "C2"
.Add "C3"
.Add "C4"
.Add "D1"
.Add "E1"
.add "F1"
.Add "F2"
.Add "F3"
.Add "G1"
.Add "G2"
.Add "G3"
.Add "G4"
.Add "G5"
End With
End Select
End Sub

Any help is appreciated.
 
J

Jean-Guy Marcil

SGT Buckeye was telling us:
SGT Buckeye nous racontait que :
Can someone look at this code and tell me why it won't work? What I

"it won't work" is not very descriptive.

What are your overall goals?
What are the expectations?
What are the actual results?
want to do is create a dropdown list in the Form Field called
"Deduction1" if anything is typed into the Form Field called "CLS1".

Sub CascadeList()
If ActiveDocument.FormFields("CLS1").TextBox.Value = 0 Then

ActiveDocument.FormFields("Deduction1").DropDown.ListEntries.Clear
Exit Sub
End If
Select Case ActiveDocument.FormFields("CLS1").Result
Case "*"
With
ActiveDocument.FormFields("Deduction1").DropDown.ListEntries
.Clear
.Add "A1"
.Add "A2"
.Add "A3"
.Add "A4"
.Add "A5"
.Add "A6"
.Add "A7"
.Add "A8"
.Add "A9"
.Add "B1"
.Add "B2"
.Add "B3"
.Add "B4"
.Add "B5"
.Add "B6"
.Add "B7"
.Add "B8"
.Add "C1"
.Add "C2"
.Add "C3"
.Add "C4"
.Add "D1"
.Add "E1"
.add "F1"
.Add "F2"
.Add "F3"
.Add "G1"
.Add "G2"
.Add "G3"
.Add "G4"
.Add "G5"
End With
End Select
End Sub

Any help is appreciated.



--

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

SGT Buckeye

SGT Buckeye was telling us:
SGT Buckeye nous racontait que :


"it won't work" is not very descriptive.

What are your overall goals?
What are the expectations?
What are the actual results?









--

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

- Show quoted text -

I will type an eight digit number into the text box called CLS1. When
I exit this form field, I want the drop down list to populate in the
form field called DEDUCTION1.
 
G

Graham Mayor

The code you posted will not do what you say you intend. You cannot achieve
your intention as stated as you can only have 25 items in a drop down field.
Had there been only 25, the following would work:

Sub CascadeList()
Dim iResult As Integer
iResult = ActiveDocument.FormFields("CLS1").Result
If iResult = 0 Then
ActiveDocument.FormFields("Deduction1").DropDown.ListEntries.Clear
Else
With ActiveDocument.FormFields("Deduction1").DropDown.ListEntries
.Clear
.Add "A1"
.Add "A2"
.Add "A3"
.Add "A4"
.Add "A5"
.Add "A6"
.Add "A7"
.Add "A8"
.Add "A9"
.Add "B1"
.Add "B2"
.Add "B3"
.Add "B4"
.Add "B5"
.Add "B6"
.Add "B7"
.Add "B8"
.Add "C1"
.Add "C2"
.Add "C3"
.Add "C4"
.Add "D1"
.Add "E1"
.Add "F1"
End With
End If
End Sub

Your requirement seems to be a strange one. Why populate a dropdown list?
Why not populate a text field (or fields) with a single result based on the
number entered? Then you could use the Case statement properly.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

SGT Buckeye

The code you posted will not do what you say you intend. You cannot achieve
your intention as stated as you can only have 25 items in a drop down field.
Had there been only 25, the following would work:

Sub CascadeList()
Dim iResult As Integer
iResult = ActiveDocument.FormFields("CLS1").Result
If iResult = 0 Then
ActiveDocument.FormFields("Deduction1").DropDown.ListEntries.Clear
Else
With ActiveDocument.FormFields("Deduction1").DropDown.ListEntries
.Clear
.Add "A1"
.Add "A2"
.Add "A3"
.Add "A4"
.Add "A5"
.Add "A6"
.Add "A7"
.Add "A8"
.Add "A9"
.Add "B1"
.Add "B2"
.Add "B3"
.Add "B4"
.Add "B5"
.Add "B6"
.Add "B7"
.Add "B8"
.Add "C1"
.Add "C2"
.Add "C3"
.Add "C4"
.Add "D1"
.Add "E1"
.Add "F1"
End With
End If
End Sub

Your requirement seems to be a strange one. Why populate a dropdown list?
Why not populate a text field (or fields) with a single result based on the
number entered? Then you could use the Case statement properly.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>






- Show quoted text

Thanks for the help. I am doing this for a form that supervisors at
my job use to challenge calls that have been monitored by our quality
assurance department. It is our checks and balance system. The CLS1
field is to identify a call's ID number and the Deduction1 field is
the different deductions that can be made on any given call. Is there
any other way I could do this?
 
G

Graham Mayor

SGT said:
Thanks for the help. I am doing this for a form that supervisors at
my job use to challenge calls that have been monitored by our quality
assurance department. It is our checks and balance system. The CLS1
field is to identify a call's ID number and the Deduction1 field is
the different deductions that can be made on any given call. Is there
any other way I could do this?

So the content of CLS1 field really has nothing to do with the selection? If
you want to persist with this method, then a logical next step would be to
separate the letters and numbers into two dropdown fields.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

SGT Buckeye

So the content of CLS1 field really has nothing to do with the selection? If
you want to persist with this method, then a logical next step would be to
separate the letters and numbers into two dropdown fields.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

This is how I have the form set up currently. The only problem is
there are instances where a single call has multiple deductions. I
wanted to be able to include multiple deduction boxes (probably 3) on
a single line with the CLS1 number. There may not be any way to do
what I want and if not, I will continue to use what I have. I was
hoping there might be a workaround.
 
G

Graham Mayor

SGT Buckeye wrote:

You can only achieve an automatic solution if the macro can work out from
the data already provided what the multiple deductions would be. The answer
would therefore have to depend on how intelligent the CLS1 numbering
actually is. If it is a manual system you are stuck with what you have.
 

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