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

Search box

P: 52
hi im trying to create a search box along with a listbox. i want to enter the name of a staff in a textbox then click a command button and all the staff with that name should pop up onto the list box. i am using Access with the VB. if possible can it be some short code.

Thank Youuuuuuuuu :~)
Jan 17 '08 #1
Share this Question
Share on Google+
4 Replies


lotus18
100+
P: 866
hi im trying to create a search box along with a listbox. i want to enter the name of a staff in a textbox then click a command button and all the staff with that name should pop up onto the list box. i am using Access with the VB. if possible can it be some short code.

Thank Youuuuuuuuu :~)
So where are the codes?

Rey Sean
Jan 17 '08 #2

P: 52
The Code is What i am look for
Jan 17 '08 #3

kadghar
Expert 100+
P: 1,295
The Code is What i am look for
in my experience, its better for the user an automatic filter, that reduces the listbox each time you write something in the textbox. That can be done writing the code in the textbox change event instead of in the command button click event. both ways the code should look like this:
(assuming your list is in myArr)
Expand|Select|Wrap|Line Numbers
  1. dim arr1() as string
  2. dim i, j as long
  3. if textbox1.text="" then 
  4.     listbox1.list=myarr : exit sub
  5. end if
  6. for i = lbound(myarr) to ubound(myarr)
  7.     if instr(myarr(i), textbox1.text) <> 0 then
  8.         j = j+1 :redim preserve arr1(1 to j)
  9.         arr1(j)=myarr(i)
  10.     end if
  11. next
  12. listbox1.clear
  13. listbox1.list= arr1
you can use a FOR EACH and will get the same result, but i find this way easier to understand.

HTH
Jan 17 '08 #4

Expert 5K+
P: 8,434
Keep in mind though, this could get expensive if the number of names is large.
Jan 18 '08 #5

Post your reply

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