I currently have a select-case that will read a name field from a recordset, as well as read a boolean value from that recordset that is suppose determine whether or not to include that field in a report that will be generated later on.
The problem is, is that in VB6, you were able to assign a boolean value to ListBox.Selected(i)
Now, I cannot for the life of me figure out what to assign it to, to select or not select that field dependent on the boolean value within the recordset.
Code:
Do Until rs_1.EOF
'Until we run out of records ...
str_FieldName = rs_1.Fields("FieldName").Value
b_IncludeField = rs_1.Fields("IncludeInBatchReport").Value
Select Case str_FieldName
Case "Sequence"
listbox_Fields.Items.Add("Sequence")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "BldgNo"
listbox_Fields.Items.Add("BldgNo")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "BldgName"
listbox_Fields.Items.Add("BldgName")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "BldgFunc"
listbox_Fields.Items.Add("BldgFunc")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "POC"
listbox_Fields.Items.Add("POC")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Phone"
listbox_Fields.Items.Add("Phone")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "AH_Phone"
listbox_Fields.Items.Add("AH_Phone")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Batch"
listbox_Fields.Items.Add("Batch")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Status"
listbox_Fields.Items.Add("Status")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Region_Req"
listbox_Fields.Items.Add("Region_Req")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Region_Alt"
listbox_Fields.Items.Add("Region_Alt")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Region_Fin"
listbox_Fields.Items.Add("Region_Fin")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Comments"
listbox_Fields.Items.Add("Comments")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
End Select
rs_1.MoveNext()
'... until we run out of records.
Loop
As you can see, I have tried SelectedItem, but that does not work of course.
You're looking for the SetSelected(index, bool) method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With