By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,218 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

Listbox Selections

P: 63
Does anyone know of a way to take the contents of a multiline textbox from a form, then when I open another form with a listbox on it, have the items matching the textbox items be higlighted in the listbox?

User opens form with textbox that has 2 items in it, say "BDU1" and "BDU2". He clicks on an Edit button and open a form that has a listbox that contains selections loaded from an Access table. I would like the "BDU1" and "BDU2" in the listbox to be selected when the form opens since it was in the textbox.

Thank you in advance for any help
Apr 17 '07 #1
Share this Question
Share on Google+
4 Replies

P: 63
My appologies. The code is written in Visual Basic 6..
Apr 17 '07 #2

Expert 5K+
P: 8,434
My appologies. The code is written in Visual Basic 6..
Thanks for telling us the version - people usually don't think of it.

Which part is the problem? Getting the lines out of the multiline textbox, or doing the selections in the listbox, or what? And do you actually want to select the items in a listbox which may also contains other items, or just populate the listbox with only these items?

(Tip - to select things in a listbox, see the .Selected property)

Edit: Sorry, I just re-read your post and see that some of these are already answered there.
Apr 17 '07 #3

P: 63
Thanks Killer42. Actually, I am not sure what the best way to get the text values other than possibly the split function as the textbox could have several selections, like BDU33, BDU31, BDU34. Each is seperated by a vbcrlf and the textbox is a multiline textbox with vertical scroll bars. The listbox on the other form is populated from a table in Access 2003 and I just want to highlight (select) the items in the listbox that are in the textbox.

To help explain, what the user is doing is opening a form that contains data. That is where the textbox is. They click on an edit button which opens another form that contains the listbox so they can edit the data that is already in the textbox. The reason for wanting to highlight the items in the list box based on the text in the textbox is so they will see what was already in the textbox and can make their changes and then save it back to the textbox. Also, when they click on the edit button, I thought having the textbox clear out it's contents and then highlight what was in the textbox in the listbox, this would prevent duplicate entries from ending up back in the textbox when they closed the edit form containing the listboxes.

Hope this makes sense.
Apr 18 '07 #4

Expert 5K+
P: 8,434
I think it sounds as though you're on the right track. I'm not going to comment on the overall situation, just the technical aspects. Or to put it another way, I'm more interested in the how than the why. (I never was much good with the “big picture”.)

I think that you're right, Split is probably the simplest way to pull the lines out of the textbox. However, I suspect it won't work out very well, because I assume (correct me if I'm wrong) that it splits on a specific character. Since the line break consists of two characters (CR+LF), this may be a problem.

Of course, you can always fall back on the simple brute-force approach. Loop through your text, character by character, and grab off each line as you hit the CR (remembering to then skip over the LF, of course). A slightly more efficient method might be to use the Instr() function to find the end of each line, and probably Left() or Mid() function to grab the line.

Selecting/highlighting the items in the listbox is simply a matter of setting their corresponding .Selected property. However, you need to set the .MultiSelect property appropriately (check your doco to determine the setting you want).

So, I suppose you can just loop through your array of entries pulled from the textbox, and for each one, loop again through the listbox contents and set .Selected(n) if it matches. If the listbox entries are unique, of course, you can drop out of the loop at that point rather than continuing through the rest of them.

Wel, hope that gives you a few ideas to play with.
Apr 19 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.