Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List box using setfocus and requery

Status
Not open for further replies.

hrg

Programmer
Jan 8, 2009
46
US
Aug 29, 2001
So basically i have two txt boxes where you type in a first name and surname (you can enter one letter so it narrows it to all names beginning with B or M).

So i have two text boxes then i click search which is a button designed and coded (not wizard).

All the names are stored in a list box. In theory what should happen is that when clicking search (once you have entered a letter or name in the text boxes)the range of names (if typed one letter) or a single name ONLY appears in the LIST box where all the names are held and when clicking on the result/returned name in the list box you can edit that record or delete it.

example

(Enter) first name : ____John_______ (txt box)

(Enter) surname: ________Smith________ (txt box)

(Click) Search (button)
_____________________________________ (list box)
List Box (before clicking) : Name
Name
Name
-------------------------------------
List Box (After clicking search) : (button)
____________________________________
(List box)
John Smith

------------------------------------

when clicking clear all the names come back into the list box.

If you need a screen print let me know i will send an e-mail (if you leave your address)

Thank you for your help.

CODING FOR SERACH BUTTON

Private Sub Cmdsearch_Click()
If IsNull(TxtCpCode) And IsNull(txtCompnm) Then
MsgBox ("Please enter Company Code or Comapny Name")
Else
Call Update
End If
End Sub

CODING FOR CALL UPDATE

Private Sub Update()
LstComp.SetFocus
LstComp.Requery

End Sub
 
Private Sub Cmdsearch_Click()
If IsNull(TxtCpCode) And IsNull(txtCompnm) Then
MsgBox ("Please enter Company Code or Comapny Name")
Else
me.lstcomp.requery
me.lstcomp.setfocus
End If
End Sub

you can also try to put this in a module and define it as a function, and then call the function. However if you do this don't forget reference the control objects correctly.

Good luck on your aplication!!
 
Do you mean that, when you click clear, you don't want the names all to come back, or do you mean that the search function is not working at all? Have fun! :eek:)

Alex Middleton
 
Hi Mate easier way

just put this in

Dim xxx As ListBox
Set xxx = Me!List1 'replace list1 with the ur listbox name xxx.Requery

thats it

When u click clear just get it to blank out the 2 boxes you have and then repeat the above after it

JB Office automation specialist
Land Rover UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top