Choosing listbox values if populated by SQL stmt

Lourry

Registered User.
Local time
Today, 01:01
Joined
May 19, 2004
Messages
41
Hello All,

Here is the code for displaying the text in my textbox:

Private Sub lstType_AfterUpdate()
Dim i As Integer
Dim j As Integer
Dim strType As String
Dim strCat As String
For i = 0 To lstCat.ListCount
If lstCat.Selected(i) Then
strCat = lstCat.ItemData(i)
End If
Next i
For j = 0 To lstType.ListCount
If lstType.Selected(j) Then
strType = lstType.ItemData(j)
End If
Next j
Me.txtComp = strCat & "-" & strType
End Sub

And lstCat is populated by hardcoding the values in manually. But lstType is populated by an SQL statment below:

Private Sub lstCat_AfterUpdate()
lstType.RowSource = "SELECT tblComp.Type " & _
"FROM tblComp " & _
"WHERE tblComp.Cat = '" & lstCat.Value & "' " & _
"ORDER BY tblComp.Type;"
End Sub

The problem is the strCat string with the hypen is showing up in the textbox but the selected item in lstType is not showing up at all. Is there a specific way to choose the specific selected value off a list that is populated by an SQL statment pulling data from a table??

Many thanks!
-Lory
 
Stupid me!

All I need to use was simply:

strCat = listCat.value
strType = lstType.value
strList = strCat & "-" & strType

Thanks anyways! :)
 

Users who are viewing this thread

Back
Top Bottom