RonZ
07-30-2010, 09:49 PM
Good Evening All -
New to the VBA thing and wanted to see if anyone could answer the question about adding an additional drop down dependent on the first drop down. This would be a variation on Fumei's code:
Option Explicit
Sub FirstFieldExit()
Dim Burglary(5) As String
Dim BurglarySec(2) As String
Dim Robbery(3) As String
Dim Assault(4) As String
Dim Theft(3) As String
Dim Vehicle(2) As String
Dim i As Integer
Dim iSec As Integer
Dim var
Dim VarSec
Burglary(0) = "RESIDENCE NIGHT (6PM-6AM)"
Burglary(1) = "RESIDENCE DAY (6AM-6PM)"
Burglary(2) = "RESIDENCE UNK TIME"
Burglary(3) = "NON-RESIDENCE NIGHT (6PM-6AM)"
Burglary(4) = "NON-RESIDENCE DAY (6AM-6PM)"
Burglary(5) = "NON-RESIDENCE UNK TIME"
Robbery(0) = "FIREARM"
Robbery(1) = "KNIFE/CUTTING"
Robbery(2) = "OTH DANGEROUS WEAPON"
Robbery(3) = "HANDS/FEET/FISTS"
Assault(0) = "FIREARM"
Assault(1) = "KNIFE/CUTTING"
Assault(2) = "OTH DANGEROUS WEAPON"
Assault(3) = "HANDS/FEET/FISTS"
Assault(4) = "NO WEAPON"
Theft(0) = "OVER $400"
Theft(1) = "LOSS BETW $200-$400"
Theft(2) = "LOSS BETW $50-$199.99"
Theft(3) = "LOSS UNDER $50"
Vehicle(0) = "Auto"
Vehicle(1) = "Trucks / Busses"
Vehicle(2) = "Motorcycle / Other"
' use the value of the dropdown to case select condition
Select Case ActiveDocument.FormFields("Dropdown1").DropDown.Value
Case 1
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 6
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Burglary(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 2
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Robbery(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 3
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 5
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Assault(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Theft(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 5
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 3
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Vehicle(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
End Select
End Sub
My puzzle is how to add an additional dependency and then wrap the whole thing in a case statement. For instance, if 'Burglary' was selected from the first drop down, and 'Force' was selected from the second, (got this much , but getting lost here) then a third drop down would be auto populated with three choices. Depending on the .Value of the concateneated first box, second box, and third box, I want to write a case statement that outputs a code.
As an example, if Burglary, Residence Day(6AM - 6PM), Force is selected, output to a text box '05-A-02'
New to the VBA thing and wanted to see if anyone could answer the question about adding an additional drop down dependent on the first drop down. This would be a variation on Fumei's code:
Option Explicit
Sub FirstFieldExit()
Dim Burglary(5) As String
Dim BurglarySec(2) As String
Dim Robbery(3) As String
Dim Assault(4) As String
Dim Theft(3) As String
Dim Vehicle(2) As String
Dim i As Integer
Dim iSec As Integer
Dim var
Dim VarSec
Burglary(0) = "RESIDENCE NIGHT (6PM-6AM)"
Burglary(1) = "RESIDENCE DAY (6AM-6PM)"
Burglary(2) = "RESIDENCE UNK TIME"
Burglary(3) = "NON-RESIDENCE NIGHT (6PM-6AM)"
Burglary(4) = "NON-RESIDENCE DAY (6AM-6PM)"
Burglary(5) = "NON-RESIDENCE UNK TIME"
Robbery(0) = "FIREARM"
Robbery(1) = "KNIFE/CUTTING"
Robbery(2) = "OTH DANGEROUS WEAPON"
Robbery(3) = "HANDS/FEET/FISTS"
Assault(0) = "FIREARM"
Assault(1) = "KNIFE/CUTTING"
Assault(2) = "OTH DANGEROUS WEAPON"
Assault(3) = "HANDS/FEET/FISTS"
Assault(4) = "NO WEAPON"
Theft(0) = "OVER $400"
Theft(1) = "LOSS BETW $200-$400"
Theft(2) = "LOSS BETW $50-$199.99"
Theft(3) = "LOSS UNDER $50"
Vehicle(0) = "Auto"
Vehicle(1) = "Trucks / Busses"
Vehicle(2) = "Motorcycle / Other"
' use the value of the dropdown to case select condition
Select Case ActiveDocument.FormFields("Dropdown1").DropDown.Value
Case 1
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 6
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Burglary(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 2
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Robbery(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 3
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 5
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Assault(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Theft(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 5
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 3
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Vehicle(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
End Select
End Sub
My puzzle is how to add an additional dependency and then wrap the whole thing in a case statement. For instance, if 'Burglary' was selected from the first drop down, and 'Force' was selected from the second, (got this much , but getting lost here) then a third drop down would be auto populated with three choices. Depending on the .Value of the concateneated first box, second box, and third box, I want to write a case statement that outputs a code.
As an example, if Burglary, Residence Day(6AM - 6PM), Force is selected, output to a text box '05-A-02'