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 when initially open

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.

Upvotes: 0

Views: 36

Answers (1)

Gustav
Gustav

Reputation: 55981

Combo88 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

Upvotes: 0

Related Questions