TheSearcher
Registered User.
- Local time
- Today, 04:52
- Joined
- Jul 21, 2011
- Messages
- 404
Hi All,
I use the following code in many different applications to display what has already been selected from a listbox while opening a form. It always works perfectly.
However, in this particular instance, all listbox values remain unselected.
This code is on the On Open event of my form. Can anyone see what I'm doing wrong?
I use the following code in many different applications to display what has already been selected from a listbox while opening a form. It always works perfectly.
However, in this particular instance, all listbox values remain unselected.
This code is on the On Open event of my form. Can anyone see what I'm doing wrong?
Code:
'*** Populate the listbox
sql1 = "SELECT tbl_ST_DDD_Modalities.Modalities "
sql1 = sql1 & "From tbl_ST_DDD_Modalities "
sql1 = sql1 & "ORDER BY tbl_ST_DDD_Modalities.SortBy;"
lst_Modalities.RowSource = sql1
lst_Modalities.Requery
'*** Grab values to display in listbox
sql1 = ""
sql1 = "SELECT tbl_Note_ST_DDD_Modalities.Modalities "
sql1 = sql1 & "FROM tbl_Note_ST_DDD_Modalities "
sql1 = sql1 & "WHERE tbl_Note_ST_DDD_Modalities.Note_Id = " & Globals.glb_NoteID
Set rs = db.OpenRecordset(sql1)
''*** Display proper Listbox values from the recordset *************************
Dim varitm As Variant
Dim SelectedID As String
Dim i As Integer
'loop the recordset
Do While Not rs.EOF
SelectedID = rs("Modalities")
For i = 0 To (lst_Modalities.ListCount - 1)
If lst_Modalities.Column(0, i) = SelectedID Then
lst_Modalities.Selected(i) = True
End If
Next i
rs.MoveNext
Loop
rs.Close