Displaying previously selected items in a list box

G

Guest

I think I have isolated the question, but I am going to include the whole sub
(which does not work, as you will see).

Dim DB As Database
Dim rs As Recordset
Dim strsql As String
Dim frm As Form

strsql = "SELECT tblAEtoAPP.txtAE, tblAEtoAPP.txtAPP_LIST " & _
"FROM tblAEtoAPP WHERE (((tblAEtoAPP.txtAE)=" & Me.Combo0 & "))"

Set DB = CurrentDb
Set rs = DB.OpenRecordset(strsql)
Set frm = Me.sfrmAUDIT_ENTITY_INFORMATION.Form

Do Until rs.EOF
If frm!List9.ItemData = txtAPP_LIST Then
frm!List9.Selected = True
End If
rs.MoveNext
Loop


In the first line after the do statement, I know I need to figure out the
row number of the entry in the list that equals the value in the field
txtAPP_LIST. Then I need to change the list9.selected(varnumber) = true.

So how do I fix the above.

Biggles
 
G

Guest

You didn't say what wasn't working or what it was that you were trying to
accomplish. It looks as though you are trying to highlight entries in a list
box that match a field in your table. If that is the case, then you might be
able to do it this way:

If rs.EOF and rs.BOF then
doevents ' in case it doesn't find anything
else
rs.movefirst
Do
For i = 1 to frm!List9.ListCount
If frm!List9.ItemData(i) = rs.Fields("txtAPP_LIST").value Then
frm!List9.Selected(i) = true
End If
Next
rs.movenext
Loop Until rs.EOF
End If


Lee Robinson
 
G

Guest

Lee

Thanks, sorry I forgot to mention what wasnt working, sometimes you see
things so much you don't see the obvious, but you did pinpoint what I needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top