G
Guest
I am trying to display the records related to a particular value in the drop
down box back into a list box. I used some code provided by Lee Robinson
which works for one of my forms, but this version does not work. I think I
have isolated the problem to the if then statement, but not sure how to test
it further to see what is going on. Here is the code:
-----------------------------------------------------
Private Sub dispapps()
Dim DB As Database
Dim rs As Recordset
Dim strsql As String
strsql = "SELECT tblBUS_SPEC_APPS.autBUS_SPEC_POS_ID,
tblBUS_SPEC_APPS.txtAPP_ID " & _
"FROM tblBUS_SPEC_APPS WHERE
tblBUS_SPEC_APPS.autBUS_SPEC_POS_ID=" & Me.Combo0
'MsgBox strsql
Set DB = CurrentDb
Set rs = DB.OpenRecordset(strsql)
'MsgBox rs.RecordCount
rs.MoveFirst
'MsgBox Me.List2.ListCount
'MsgBox rs.Fields("txtAPP_ID")
Do Until rs.EOF
For i = 0 To Me.List2.ListCount - 1
MsgBox "txtappid = " & rs.Fields("txtapp_id")
MsgBox "i = " & i
MsgBox "itemdata = " & Me.List2.ItemData(i)
If Me.List2.ItemData(i) = rs.Fields("txtAPP_ID").Value Then
'**problem line
MsgBox "yep, they are equal"
Me.List2.Selected(i) = True
End If
Next
rs.MoveNext
Loop
Me.Refresh
End Sub
------------------------------------------------
As you can see, I put in a lot of message boxes to display what each value
was at the time. When the Do Loop and If Then statements are cycling, I can
see where the txtAPP_id and the ItemData(i) are the same values, but I never
see the msgbox "Yep, they are equal" so the '** problem line does not appear
to be evaluating correctly. I did check and each is a value, How can I test
this better to figure out the problem, or can someone see the problem?
down box back into a list box. I used some code provided by Lee Robinson
which works for one of my forms, but this version does not work. I think I
have isolated the problem to the if then statement, but not sure how to test
it further to see what is going on. Here is the code:
-----------------------------------------------------
Private Sub dispapps()
Dim DB As Database
Dim rs As Recordset
Dim strsql As String
strsql = "SELECT tblBUS_SPEC_APPS.autBUS_SPEC_POS_ID,
tblBUS_SPEC_APPS.txtAPP_ID " & _
"FROM tblBUS_SPEC_APPS WHERE
tblBUS_SPEC_APPS.autBUS_SPEC_POS_ID=" & Me.Combo0
'MsgBox strsql
Set DB = CurrentDb
Set rs = DB.OpenRecordset(strsql)
'MsgBox rs.RecordCount
rs.MoveFirst
'MsgBox Me.List2.ListCount
'MsgBox rs.Fields("txtAPP_ID")
Do Until rs.EOF
For i = 0 To Me.List2.ListCount - 1
MsgBox "txtappid = " & rs.Fields("txtapp_id")
MsgBox "i = " & i
MsgBox "itemdata = " & Me.List2.ItemData(i)
If Me.List2.ItemData(i) = rs.Fields("txtAPP_ID").Value Then
'**problem line
MsgBox "yep, they are equal"
Me.List2.Selected(i) = True
End If
Next
rs.MoveNext
Loop
Me.Refresh
End Sub
------------------------------------------------
As you can see, I put in a lot of message boxes to display what each value
was at the time. When the Do Loop and If Then statements are cycling, I can
see where the txtAPP_id and the ItemData(i) are the same values, but I never
see the msgbox "Yep, they are equal" so the '** problem line does not appear
to be evaluating correctly. I did check and each is a value, How can I test
this better to figure out the problem, or can someone see the problem?