Thanks for the reply. My database contains 10 names and their threshold values. When i select a name and click a "Present tone" button, it should show a smile if it corresponds to the threshold values in the database. I don't know how to link my database file to the program.
Hi tigger,
First, it's better for you to get your combobox's list directly from your database. It means that every time your database changed (e.g: added new names or deleted a name), the combobox will be updated automatically.
To link your combobox to your database, you can use these codes:
Private Sub Form_Load()
Dim conec As New ADODB.Connection
Dim rs As New ADODB.Recordset
conec.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ='" & App.Path & "\STUDENTS.mdb'"
conec.CursorLocation = adUseClient
conec.Open
rs.Open "select STUDENTNAME from STUDENTDATA", conec, adOpenKeyset, adLockOptimistic
If rs1.EOF = False Then
Do Until rs1.EOF
Combo1.AddItem rs!KD_SALES
rs.MoveNext
Loop
rs.Close
End If
End Sub
And to link your form to your database and show the data that match the name you've choosed in the textbox:
Private Sub Combo1_Click() '--> show the data straight away after you choose a name from combo1
Dim conec As New ADODB.Connection
Dim rs2 As New ADODB.Recordset
conec.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ='" & App.Path & "\STUDENTS.mdb'"
conec.CursorLocation = adUseClient
conec.Open
rs2.Open "select * from STUDENTDATA where STUDENTNAME = '" & Combo1.Text & "'", conec, adOpenKeyset, adLockOptimistic
If rs2.EOF = False Then
Text1.Text = rs2!STUDENTNAME
Text5.Text = rs2!STUDENTADDRESS
rs2.MoveNext
rs2.Close
End If
End Sub
The bold text is used for show data from your database to textboxes. You may change it if you want to do other actions.
I hope it helps.
Nairda