PDA

View Full Version : [SLEEPER:] Getting dropdown to repeat in new table row



Bernadette
02-12-2025, 01:45 PM
I have put the following code in a Dropdown list in the “Change” event. It works great but when the “Add Row” button is clicked the items in the dropdown of the new row do not appear. How do I get the code to repeat for each row? Any help is greatly appreciated!



var newVal = this.boundItem(xfa.event.newText); // Stores the dropdown value when the user selects something from the drop down list.
switch (newVal) // Depending upon the selections made in the Sector dropdown populates the Table2.Row1.GL_DropDown field
{
case "1":
Table2.Row1.GL_DropDown.clearItems();
Table2.Row1.GL_DropDown.rawValue =null;
Table2.Row1.GL_DropDown.addItem("Option 1")
Table2.Row1.GL_DropDown.addItem("Option 2")
Table2.Row1.GL_DropDown.addItem("Option 3")
Table2.Row1.GL_DropDown.addItem("Option 4")
break;
case "2":
Table2.Row1.GL_DropDown.clearItems();
Table2.Row1.GL_DropDown.rawValue =null;
Table2.Row1.GL_DropDown.addItem("Module 1")
Table2.Row1.GL_DropDown.addItem("Module 2")
Table2.Row1.GL_DropDown.addItem("Module 3")
Table2.Row1.GL_DropDown.addItem("Module 4")
break;

case "3":
Table2.Row1.GL_DropDown.clearItems();
Table2.Row1.GL_DropDown.rawValue =null;
Table2.Row1.GL_DropDown.addItem("Station 1")
Table2.Row1.GL_DropDown.addItem("Station 2")
Table2.Row1.GL_DropDown.addItem("Station 3")
Table2.Row1.GL_DropDown.addItem("Station 4")
break;
default:
break;
}

June7
02-12-2025, 04:37 PM
This is code behind a Word document?

Could you attach that file?

Bernadette
02-13-2025, 06:56 AM
So sorry I posted this in the wrong forum!

Aussiebear
02-14-2025, 02:03 AM
Maybe something like this (using vba)



Private Sub Worksheet_Change(ByVal Target As Range)
Dim tbl As ListObject
Dim newRow As Range
Dim dropdownColumn As Range
' The column where you want the dropdown
' Set the table object (replace "MyTable" with your table's name)
Set tbl = ThisWorkbook.Sheets("Sheet1").ListObjects("MyTable")
' Adjust sheet name abd table name to suit
' Set the column where you want the dropdown (e.g., column B). Use column number.
Set dropdownColumn = tbl.DataBodyRange.Columns(2)
' ADJUST COLUMN NUMBER (2 = Column B, 3 = C, etc.)
' Check if the change occurred within the table's data body
If Not Intersect(Target, tbl.DataBodyRange) Is Nothing Then
' Check if a new row was added (more rows in the table now)
If tbl.DataBodyRange.Rows.Count > Target.Rows.Count Then
' Find the newly added row(s)
Set newRow = Intersect(Target, tbl.DataBodyRange)
' Loop through the newly added rows and add data validation
Dim cell As Range
For Each cell In newRow.Cells
' Only apply to the dropdown column
If Not Intersect(cell, dropdownColumn) Is Nothing Then
With cell.Validation
.Delete
' Clear any existing validation
.Add xlValidateList, xlValidAlertStop, xlBetween, "=MyDropdownList"
' Use your named range.
' Adjust named range if needed
.ErrorMessage = "Invalid Input"
.ErrorTitle = "Selection Error"
End With
End If
Next cell
End If
End If
End Sub

Aflatoon
02-14-2025, 03:13 AM
That looks like code for an Adobe form to me?