I've come up with this sub routine that i call from a command button which populates the list box:
Sub VbColour1()
'---------------------------------------------------------
On Error GoTo Err
If Forms!frmAtaGlance!lstDriverGlance1.RowSource = Null Then
Forms!frmAtaGlance!lstDriverGlance1.BackColor = vbWhite
Else
Forms!frmAtaGlance!lstDriverGlance1.BackColor = vbRed
End If
You can set the Back Colour of the list box whilst the form is in design view, or you can set via one of the form events with something like;
Code:
If Me.ListBoxName.Recordset.RecordCount = 0 Then
Me.ListBoxName.BackColor = 16711935 [COLOR="SeaGreen"]'Set BackColor if no data[/COLOR]
Else
Me.ListBoxName.BackColor = 16776960 [COLOR="SeaGreen"]'Set BackColor if data[/COLOR]
End If
This is really weird.
I tried:
Forms!frmAtaGlance!lstDriverGlance1.Recordset.RecordCount = 0 and i get the following error:
Error 3420: Object Invalid or no longer set
If i use IsNull(Forms!frmAtaGlance!lstDriverGlance1) then it colours the listbox even if it doesn't have any data in it.
My sub-routine now works perfectly!!
It looks like this now:
Sub VbColour1()
'---------------------------------------------------------
On Error GoTo Err
If Forms!frmAtaGlance!lstDriverGlance1.ListCount > 0 Then
Forms!frmAtaGlance!lstDriverGlance1.BackColor = 16711935 '(If there is data, then use this colour)
Else
Forms!frmAtaGlance!lstDriverGlance1.BackColor = 16777215 '(If there is no data, then use this colour)
End If