Unexpected NULL result

J

John

Hi

In Access 97 I am trying below code;

Private Sub Clientlist_DblClick(Cancel As Integer)

CurStaff = Me.ClientList.Value
MsgBox CurStaff

End Sub

Problem is that even though the ClientList list is populated, when I
double-click on list the value of CurCleint comes out as Null resulting in
error on line MsgBox CurClient. What is the problem and how can I fix it?

Thanks

Regards
 
S

SteveM

Clicking once selects an item, clicking again de-selects it so if you
double-click on an item it is no longer selected.

Steve
 
J

John

I have now added a button to form and am using the below code;

Private Sub Command94_Click()
If IsNull(Me.ClientList.Value) Then
Exit Sub
End If

CurCleint = Me.ClientList.Value
End Sub

Me.ClientList.Value still comes out as null even though I have made a point
of highlighting (selecting) one of the items in the list. I am really
confused. Any help to resolve this would be appreciated.

Thanks

Regards
 
R

Rob Parker

Hi John,

What you are probably wanting is the ItemData of the selected item in the
list box. To do that, you need to access it via the ItemsSelected property
of the listbox.

Assuming that CurStaff is declared somewhere, this will return the value of
the selected item (or the first item if the listbox has either simple or
extended multi-select enables) in the list box:
curstaff = Me.ClientList.ItemData(ClientList.ItemsSelected.Item(0))

If you double-click in an empty area of the listbox when nothing is
selected, this will throw an error.

HTH,

Rob
 
J

John

Me.ClientList.ItemData(ClientList.ItemsSelected.Item(0)) comes out as Null
even though an element is selected in the list.

Regards
 
R

Rob Parker

Seems strange. The code I posted worked in a test here.

Is it possible that your listbox has a null value in the bound column?

Rob
 
Top