NorthbyNorthwest
Board Regular
- Joined
- Oct 27, 2013
- Messages
- 173
- Office Version
- 365
Hi, everyone. I have a multipage form with a variety of controls. This includes several multiselect list boxes. The list boxes have two columns. The first column has number, the second a narrative. When end users make one or more selections from a list box the first column of the selections are copied to a worksheet. The code encloses numbers in brackets, for example if multiple selections were made the worksheet cell might read: [201][217][224]. If no selections then a hyphen is copied to the worksheet. (It’s a placeholder. I didn’t want to leave cells blank.) I have the following code to accomplish this task. Note: Button 1 is a “yes”. Button 3 is a “N/A.” Button 2 (else in the code below) is the “No” button.
My problem. The form is designed to both add data to a worksheet and update data in a worksheet. So, when end users search for a record with user form the data is copied/written/read back to the form controls. I can do this other controls (textboxes, comboboxes, option buttons). But not the listboxes. Is there any way to reverse engineer the code above? If no, can some suggest something else? As it stands now, when the end user updates an entry, they have to go through process of reselecting listbox item(s) because I cannot write the values back to the form.
VBA Code:
If optButton1 = True Or optButton3 = True Then
ActiveCell.Offset(0, 55).value = "-"
Else
myVar = ""
For X = 0 To Me.lbxList1.ListCount - 1
If Me.lbxList1.Selected(X) Then
If myVar = "" Then
myVar = "[" & Me.lbxList1.List(X, 0) & "]"
Else
myVar = myVar & "[" & Me.lbxList1.List(X, 0) & "]"
End If
End If
Next X
ActiveCell.Offset(0, 55).value = myVar
End If
My problem. The form is designed to both add data to a worksheet and update data in a worksheet. So, when end users search for a record with user form the data is copied/written/read back to the form controls. I can do this other controls (textboxes, comboboxes, option buttons). But not the listboxes. Is there any way to reverse engineer the code above? If no, can some suggest something else? As it stands now, when the end user updates an entry, they have to go through process of reselecting listbox item(s) because I cannot write the values back to the form.