admin管理员组文章数量:1287285
When I open update form, the list box isn't highlighting the selected boxes, but when I enter design view and then back into form view, then it does highlight and the values which are selected by user, if i try to fix the error then other parts of the code break.
this is the code:
Private Sub Form_Load()
Me.Combo58 = Me.Combo58.ItemData(0)
Me.Form.SetFocus
Dim strSQL As String
Dim result As DAO.Recordset
strSQL = "SELECT BookingHorse.[HorseiD], BookingHorse.[Bookingreference] FROM BookingHorse WHERE (((BookingHorse.[Bookingreference])=" & Combo58.ItemData(0) & "));"
Set result = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
Do While Not result.EOF
For p = 0 To Me.List46.ListCount - 1
If CStr(List46.ItemData(p)) = CStr(result.Fields(0).Value) Then
List46.Selected(p) = True
End If
Next p
result.MoveNext
Loop
Dim strSQL1 As String
Dim result1 As DAO.Recordset
strSQL1 = "SELECT BookingEmployee.EmployeeID FROM BookingEmployee WHERE (((BookingEmployee.BookingReference)=" & Combo58.ItemData(0) & "));"
Set result1 = CurrentDb.OpenRecordset(strSQL1, dbOpenDynaset)
Do While Not result1.EOF
For q = 0 To Me.List44.ListCount - 1
If CStr(List44.ItemData(q)) = CStr(result1.Fields(0).Value) Then
'MsgBox ("Match")
List44.Selected(q) = True
End If
Next q
result1.MoveNext
Loop
End Sub
I tried to redo my queries and use other code to find how to highlight list boxes. I tried adding a DoCmd.Close and a DoCmd.FormOpen immediately after the original DoCmd.FormOpen.
When I open update form, the list box isn't highlighting the selected boxes, but when I enter design view and then back into form view, then it does highlight and the values which are selected by user, if i try to fix the error then other parts of the code break.
this is the code:
Private Sub Form_Load()
Me.Combo58 = Me.Combo58.ItemData(0)
Me.Form.SetFocus
Dim strSQL As String
Dim result As DAO.Recordset
strSQL = "SELECT BookingHorse.[HorseiD], BookingHorse.[Bookingreference] FROM BookingHorse WHERE (((BookingHorse.[Bookingreference])=" & Combo58.ItemData(0) & "));"
Set result = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
Do While Not result.EOF
For p = 0 To Me.List46.ListCount - 1
If CStr(List46.ItemData(p)) = CStr(result.Fields(0).Value) Then
List46.Selected(p) = True
End If
Next p
result.MoveNext
Loop
Dim strSQL1 As String
Dim result1 As DAO.Recordset
strSQL1 = "SELECT BookingEmployee.EmployeeID FROM BookingEmployee WHERE (((BookingEmployee.BookingReference)=" & Combo58.ItemData(0) & "));"
Set result1 = CurrentDb.OpenRecordset(strSQL1, dbOpenDynaset)
Do While Not result1.EOF
For q = 0 To Me.List44.ListCount - 1
If CStr(List44.ItemData(q)) = CStr(result1.Fields(0).Value) Then
'MsgBox ("Match")
List44.Selected(q) = True
End If
Next q
result1.MoveNext
Loop
End Sub
I tried to redo my queries and use other code to find how to highlight list boxes. I tried adding a DoCmd.Close and a DoCmd.FormOpen immediately after the original DoCmd.FormOpen.
Share Improve this question edited Feb 23 at 18:32 braX 11.8k5 gold badges22 silver badges37 bronze badges asked Feb 23 at 18:32 caoimhe ni loingsighcaoimhe ni loingsigh 1 1 |1 Answer
Reset to default 0Combo88 probably has no value. Try inserting a line to debug and study the SQL:
strSQL = "SELECT BookingHorse.[HorseiD], BookingHorse.[Bookingreference] FROM BookingHorse WHERE (((BookingHorse.[Bookingreference])=" & Combo58.ItemData(0) & "));"
Debug.Print "SQL: " & strSQL
本文标签:
版权声明:本文标题:vba - The list Box isn't highlighting but when I hit on it again in design view and back to form view it works but not w 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741306937a2371423.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
List44
etc. – Andre Commented Feb 24 at 12:20