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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT DATA FROM TABLE USING LIST BOX

Status
Not open for further replies.

pelagic

Programmer
Nov 7, 2002
97
US
Hi All,
I have table tblAnimalName, which include the following
ANIMAL_NAME PRICE
CAT 100
CAT 150
CAT 75
CAT 50
DOG 200
DOG 150
DOG 175
DOG 50
LION 1000
LION 750
I also have a Visual basic list box named lstAnimalName, which include the following:
CAT
DOG
LION
How do I generate data from tblAnimalName from item that is
not select from lstAnimalName?
For example: If I selected DOG and LION from lstAnimalName I would get all CAT from tblAnimalName.

thanks for your time,
regards

 
Hi All,
I have found the solution for my problem.
If any one is having the same problem they can use this code:
In the click event do the following

Private Sub cmdGetDataClick()
Dim item as integer

For item = 0 To (lstAnimalName.ListCount - 1)
If lstAnimalName.Selected(item) = False Then
cn.Execute "INSERT INTO tblNewTable " & _
"SELECT * FROM tblAnimalName WHERE [ANIMAL_NAME]= & _
"'" & lstAnimalName.List(item) & "'"
End If
Next item

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top