|
-
Aug 20th, 2003, 12:02 PM
#1
Thread Starter
Member
Listbox Selections from Recordset - RESOLVED
Let me see if I can explain this without sounding like a total dolt.
I have a list box that is populated with five options. I select two of the five options and these selections are written back to the database. No problems here.
My question is if I want to edit this record, can I show the original five options with the two I’ve previously selected already selected / highlighted?
Clear as mud?
Last edited by Suidae; Aug 21st, 2003 at 12:27 PM.
I'm a misanthropic philanthropist!
Frog, the only white meat...
-
Aug 20th, 2003, 12:07 PM
#2
Fanatic Member
Yes you can. Just place the five options in the listbox. Then query your database for the appropriate records. Then you would use two for loops, the outer for loop you can use to loop through your recordset, and the inner to loop through your listbox. If any item in the listbox matchs the a field in the recordset then change the selected property for that item to equal true.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 20th, 2003, 12:18 PM
#3
Fanatic Member
Here is an example, but obviously you would use your recordset to query a database instead of the way I did it and made it a disconnected recordset.
VB Code:
Dim rsList As New ADODB.Recordset
'instead of appending fields you would do a query and open
'your recordset with the appropriate fields.
rsList.Fields.Append "Name", adBSTR
rsList.CursorType = adOpenStatic
rsList.LockType = adLockOptimistic
rsList.Open
'I am adding two records for test data, but you would
'already have data from your query
rsList.AddNew
rsList.Fields("Name") = "Greg"
rsList.AddNew
rsList.Fields("Name") = "Joe"
'now just loop through and highlight any items that are equal
rsList.MoveFirst
For i = 1 To rsList.RecordCount
For n = 0 To List1.ListCount
If List1.List(n) = rsList("Name") Then
List1.Selected(n) = True
Exit For
End If
Next
rsList.MoveNext
Next
rsList.Close
Set rsList = Nothing
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 21st, 2003, 12:28 PM
#4
Thread Starter
Member
Many thanks Maldrid.. worked like a charm
I'm a misanthropic philanthropist!
Frog, the only white meat...
-
Aug 21st, 2003, 01:09 PM
#5
Fanatic Member
Glad I could help
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|