I have two ComboBoxes in Excel (ContractTypeComboBox & PositionComboBox), and I need the 2nd ComboBox (PositionComboBox) to populate dynamically based on each of the selection in the 1st ComboBox (ContractTypeComboBox), which is based on a table I have setup on another worksheet (Tables).
However, I keep getting the "Run-time error'70' : Permission denied.", when selecting any of the options in the ContractTypeComboBox.
Please can somebody help. I have pasted the code below :
Option Explicit
Private Sub ContractTypeComboBox_Change()
Dim FixedTermContract As Range
Dim FixedTermContractTTO As Range
Dim Permanent As Range
Dim PermanentTTO As Range
Dim SupportWorker As Range
Dim Trainee As Range
Dim wbNurseryNewEmployeeForm As Workbook
Dim wsNewForm As Worksheet
Dim wsNNEFTables As Worksheet
' Set this Workbook's name.
Set wbNurseryNewEmployeeForm = ActiveWorkbook
' Set Worksheet name(s).
Set wsNewForm = wbNurseryNewEmployeeForm.Worksheets("New Form")
Set wsNNEFTables = wbNurseryNewEmployeeForm.Worksheets("Tables")
' Populate the Position ComboBox drop-down list.
If wsNewForm.Range("ContractType").Value = "Permanent" Then
For Each Permanent In wsNNEFTables.Range("Permanents")
PositionComboBox.AddItem Permanent.Offset(0, -1).Value
Next Permanent
End If
If wsNewForm.Range("ContractType").Value = "Permanent (TTO)" Then
For Each PermanentTTO In wsNNEFTables.Range("PermanentsTTO")
PositionComboBox.AddItem PermanentTTO.Offset(0, -2).Value
Next PermanentTTO
End If
If wsNewForm.Range("ContractType").Value = "Support Worker" Then
For Each SupportWorker In wsNNEFTables.Range("SupportWorkers")
PositionComboBox.AddItem SupportWorker.Offset(0, -3).Value
Next SupportWorker
End If
If wsNewForm.Range("ContractType").Value = "Fixed Term Contract" Then
For Each FixedTermContract In wsNNEFTables.Range("FixedTermContracts")
PositionComboBox.AddItem FixedTermContract.Offset(0, -4).Value
Next FixedTermContract
End If
If wsNewForm.Range("ContractType").Value = "Fixed Term Contract (TTO)" Then
For Each FixedTermContractTTO In wsNNEFTables.Range("FixedTermContractsTTO")
PositionComboBox.AddItem FixedTermContractTTO.Offset(0, -5).Value
Next FixedTermContractTTO
End If
If wsNewForm.Range("ContractType").Value = "Trainee" Then
For Each Trainee In wsNNEFTables.Range("Trainees")
PositionComboBox.AddItem Trainee.Offset(0, -6).Value
Next Trainee
End If
End Sub
Bookmarks