PDA

View Full Version : [need help] Data Bound List Control


seioh
03-05-04, 03:20 PM
hi, i am a beginner in visual basic
so here's my problem....

i am trying to make a DBList that links to a database in MSAccess
the table in the database contains 4 columns.
what i want to do is that when i click on the item on the list,
the other fields of the record would show up correctly in text boxes.

i have been trying to do that by putting the primary key field
as the ListField. but i can only get the ListField to change.
the other way i tried is to put the BoundColumn as another field.
then i can get two correct fields when i click on the list...

is there any way that i can display all the fields in the record??

i hope u can understand my problem(i am not good at English)
and thx for any help at all~~~

dazz417
04-30-04, 10:54 AM
hi, i am a beginner in visual basic
so here's my problem....

i am trying to make a DBList that links to a database in MSAccess
the table in the database contains 4 columns.
what i want to do is that when i click on the item on the list,
the other fields of the record would show up correctly in text boxes.

i have been trying to do that by putting the primary key field
as the ListField. but i can only get the ListField to change.
the other way i tried is to put the BoundColumn as another field.
then i can get two correct fields when i click on the list...

is there any way that i can display all the fields in the record??

i hope u can understand my problem(i am not good at English)
and thx for any help at all~~~

how about writing an SQL statement that uses the criteria in the listbox to query the database. E.g


Option Explicit
Dim Rs As ADODB.Recordset
Dim ConStr As String

Private Sub Form_Load()
Set Rs = New ADODB.Recordset

'set ConStr to the location of your database
ConStr = "C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"

Rs.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ConStr

'Here the TABLE_NAME is Titles and the COLUMN is Title
Rs.Open "SELECT Title FROM Titles"

Do Until Rs.EOF
List1.AddItem Rs!Title
Rs.MoveNext
Loop

Rs.Close
End Sub

Private Sub List1_Click()
Dim strSel As String
strSel = List1.Text

'replace the value of ISBN and PubID with the various fields you require
Rs.Open "SELECT ISBN, PubID FROM Titles Where Title='" & strSel & "';"

Text1.Text = Rs!isbn
Text2.Text = Rs!pubid

Rs.Close
End Sub


Hope this helps