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

pick selected values from a list populated by SQL stmt

Status
Not open for further replies.

Lourry

Technical User
Jul 25, 2003
84
CA
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
 
Let's try an update to your code:

Code:
For i = 0 To lstCat.ListCount
   If lstCat.Selected(i) Then
      strCat = lstCat.ItemData(i)
      [highlight]i = lstCat.ListCount[/highlight]
   End If
Next i
For j = 0 To lstType.ListCount
   If lstType.Selected(j) Then
      strType = lstType.ItemData(j)
      [highlight]j = lstType.ListCount[/highlight]
   End If
Next j

Add the highlighted lines of code. Let's see if that works for you.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top