Why don't you just use one listbox, and one text box. The listbox to list all the names and the text box to show the grade of the name you choose. If you do it this way then you can use the CHANGE event for the listbox to query the database for the Grade of the selected Name. Something like this:
Private Sub dlstName_Change()
Dim cmd As ADODB.Command, cnn As ADODB.Connection
Dim a As ADODB.Recordset, st As String, found As Boolean
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
If Not IsNull(dlstName) And dlstName <> Empty Then
cnn.Open "Provider = SQLOLEDB ;PERSIST SECURITY INFO = FALSE;" & _
"USER ID = sa;Initial catalog = timersql;" & _
"INITIAL FILE NAME = C:\MSSQL7\Data\someDatabase.mdf"
cmd.ActiveConnection = cnn
cmd.CommandText = "spGetGradesforName"
cmd.CommandType = adCmdStoredProc
Set a = cmd.Execute(, CStr(dlstName))
If Not a.EOF Then
txtGrade = CStr(a!Grade)
End If
End If
End Sub
Enter your message below
Sign in or Join us (it's free).