I've got a Word userform with 2 listboxes. The code for the two listboxes is identical. I populate each listbox from an array of strings, and I set a default value for each listbox (e.g., ctlList1.Value = Choice1) before I Show the dialog. The dialog duly displays, the correct values show as selected, so far so good.
The problem is that if I simply hit the OK button to accept both default values (which hides the dialog, at which point the code continues), the value of one (and only one) of the listboxes is always an empty string, rather than the default value (even though the default value is always correctly and visibly selected on the screen).
To add further confusion, depending on which items in the lists I choose as the default values, the empty listbox is sometimes the first one and sometimes the second one.
If I affirmatively (and redundantly, if things were working properly) select the default value in the listbox that would otherwise turn up empty, the macro works as it should.
As a final confusing note (and possible further clue), if I set a breakpoint on the frm.lblList1 = strLabel1 line (see my code, below) and hover over ctlList1.Value, Choice1, ctlList2.Value and Choice2 (in the preceding 6 lines), Choice1 and Choice2 are always the correct strings, while one of the two .Value references is always correct and the other is always an empty string. (And again, whether it's ctlList1.Value or ctlList2.Value that's empty varies, depending on which list items I've chosen as the default values). So it looks from this like the problem has already occurred before the dialog shows (since the .Show line comes later; see below) -- and yet the default value is correctly displayed onscreen for BOTH listboxes.
Here's my code. The commented lines are my kludgey "fix" for the problem, but they shouldn't be necessary. Anyone know what the real problem is?
Sub ShowFrm2Lists(ListArray1 As Variant, ListArray2 As Variant, _
Choice1 As Variant, Choice2 As Variant, _
strLabel1 As String, strLabel2 As String)
Dim frm As UserForm
Dim ctlList1 As ListBox, ctlList2 As ListBox
Set frm = frm2Lists
Set ctlList1 = frm.lstList1
Set ctlList2 = frm.lstList2
ctlList1.List() = ListArray1
ctlList2.List() = ListArray2
If Not IsNull(Choice1) Then
ctlList1.Value = Choice1
If Not IsNull(Choice2) Then
ctlList2.Value = Choice2
frm.lblList1 = strLabel1
frm.lblList2 = strLabel2
If Not IsLoaded("frm2Lists") Then
Choice1 = Null
Choice2 = Null
' If ctlList1.Value <> "" Then
Choice1 = ctlList1
' End If
' If ctlList2.Value <> "" Then
Choice2 = ctlList2
' End If