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

List box selection problem... 1

Status
Not open for further replies.

thetambarineman

Technical User
Feb 29, 2000
63
GB
Hello all,
the following is some code that ive wrote to catch a search for certain elements that exist in a database. The thing is that it contains too many IF...THEN...ELSE statements!
Which isnt conducive to good code.. Can anyone suggest a way around this... Perhaps a case statement???

If List1.Selected(0) = True Then
Data1.Recordset.FindFirst "employer_name='" & List1.Text & "'"

Else
If List1.Selected(1) = True Then
Data1.Recordset.FindFirst "employer_name='" & List1.Text & "'"

Else

If List1.Selected(2) = True Then
Data1.Recordset.FindFirst "employer_name='" & List1.Text & "'"

Else

If List1.Selected(3) = True Then
Data1.Recordset.FindFirst "employer_name='" & List1.Text & "'"

End If

End If
End If

End If

Thanks in advance...

Paul...

 
'Hi,
'Try this. Modify if needbe. I assume that when you select an item from the listbox you want to do the search. if so then...

dim Criteria as string
Criteria = list1.list(list1.listindex).Selected
Data1.Recordset.FindFirst "employer_name=", Criteria

Have a good one!
BK
 
Sorry, I realized I made a typo...

Private Sub List1_Click()
Dim Criteria As String

Criteria = List1.List(List1.ListIndex)
Data1.Recordset.FindFirst "Author ='" & Criteria & "'"
End Sub
 
Thanx very much for your reply to my question. It was most helpful..!

As you might have guessed im a beginner at SQL and was wondering how one might construct an SQL statement that matches partial data from a database.
Say the user types in "tek" and the database entry is "Tek-tips" - the SQL would pick this up and act display the tek-tips entry even though all that has been entered is "Tek"

Thanks in advance...

Paul...
 

You can use this code:

If you want to search in a database using dbgrid or
msflexgrid you can use:

dim sql1 As String
dim database1 as database

set database1 = opendatabase (app.path+"\database.mdb")
sql1="SELECT * FROM table WHERE employer_name='" & _ List1.List(List1.ListIndex) & "')"

database1.execute sql1

database1.close

... and refresh the dbgrid or flexgrid.

I hope you like this code.
Carlos
 
If you use a dblistbox, it is tied to the db. Just clicking on the name in the list box should bring up the record which would be displayed in db text boxes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top