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

trouble Using combo list to search a file in the DB

Status
Not open for further replies.

nkyeshi01

Programmer
Nov 4, 2004
29
US
Hello all!

when I click an item in the combo list (drop down list) It looks up for the file and it displays the information in the correspondig text boxes but it erases the combo text. How can I make the code to leave it there???

this is the code :

Private Sub Combo1_Click()
Dim var As String

var = Combo1.Text
Data1.Recordset.CancelUpdate
Do Until var = Combo1.Text
Data1.Recordset.MoveNext
Loop
End sub



thank you all in advance

EP
 
Im not sure but the above loop will never work. I am sure this is only a code snippet but in the exmaple you have given :-

Var=Combo1.Text

Do until var=combo1.text (This will alwasy be true so loop will never run)
Data1.Recordset.movenext
Loop
 
The thing is that I need to go into the loop so it can move trough the database and find the file that I need so it can be displyed into the corresponding text boxes

Thank you for responding

EP
 
Can you do a select statement against the database when the user selects the item in the combobox?

This will probably be more efficient than selecting all the records and then displaying the one you need when you find it.
 
ok. I assume at the moment you are selecting all the records you could ever need for this from the database. Am I right?

Are you then populating the combobox with for example a name. When the person clicks on this name you are looping through the recordset until the record matches the one in the combobox. Am I on the right track so far?

What I am suggesting is that you dont open a recordset until you have selected the name from the list.

What you could do is open a recordset to populate the names for example from the database into the combobox control then kill the recordset.

Then the user selects an item from the combobox and in the click event you then open up another recordset with the name selected as an argument in the select statement.

eg

"Select * from tblNames WHERE sName = " & combo1.text

This would be a more effecient way of querying the database.

Any good for you?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top