Problem counting items in List Box

S

Silvio

I have a List Box populated by an SQL statement based on another combo box
AfterUpdate event (Me.ListServices.RowSource = "SELECT tblServices.ServiceID,
tblServices.DateIn FROM tblAdoptions INNER JOIN tblServices ON
tblAdoptions.AdoptID = tblServices.Adopt_ID WHERE
(((tblAdoptions.Volunteer_ID)=[Forms]![frmServicesToClose]![VolunteerID]));
".

The list is populated with the correct items. So far, no problem.

I then run a code when clicking on an item in the list (on Click event). Of
course, if the list is empty then the code should not run. The problem is
that even when there are items in the list box the code does not run.


Private Sub ListServices_Click()

If Me.ListServices.ItemsSelected.Count = 0 Then
Exit Sub
Else
Me.frmServicesSub.SourceObject = "frmServicesSub"
Me.frmServicesSub.Form.Filter = "[ServiceID] = " & Me.ListServices.Column(0)
Me.frmServicesSub.Form.FilterOn = True
End If
End Sub

The List Box Prop. are as follow:
Row Source Type: Table/Query
Row Source: whatever the SQL code will insert here.


I have used .ItemsSelected.Count = 0 in other form before without any
problem, but in this specific scenario it is not cooperating with me. It
appear like the count is always 0.

Any idea how to solve this problem?
 
K

Klatuu

It is probably running. Have you run it in debug mode to see what happens.
What you are testing for here:

If Me.ListServices.ItemsSelected.Count = 0 Then

Is whether or not any items in the last have been selected by the use, not
whether there are any items in the list. If that is what you want, then the
test should be:

If Me.ListServices.ListCount = 0 Then
 
S

Silvio

Klatuu, the list only has between 0-5 items when populate and right now I
only have 10 records in my DB.
In debug mode shows I get itemsselected.count = 0 even though and I did
click on an item from the list, therefore the count should be = 1
The problem with ListCount is that it always returns a count of = 1 as
minimum. It appears that the List Box always has an empty item in it, and
that item is counted by the the ListCount function even if is null.




Klatuu said:
It is probably running. Have you run it in debug mode to see what happens.
What you are testing for here:

If Me.ListServices.ItemsSelected.Count = 0 Then

Is whether or not any items in the last have been selected by the use, not
whether there are any items in the list. If that is what you want, then the
test should be:

If Me.ListServices.ListCount = 0 Then

--
Dave Hargis, Microsoft Access MVP


Silvio said:
I have a List Box populated by an SQL statement based on another combo box
AfterUpdate event (Me.ListServices.RowSource = "SELECT tblServices.ServiceID,
tblServices.DateIn FROM tblAdoptions INNER JOIN tblServices ON
tblAdoptions.AdoptID = tblServices.Adopt_ID WHERE
(((tblAdoptions.Volunteer_ID)=[Forms]![frmServicesToClose]![VolunteerID]));
".

The list is populated with the correct items. So far, no problem.

I then run a code when clicking on an item in the list (on Click event). Of
course, if the list is empty then the code should not run. The problem is
that even when there are items in the list box the code does not run.


Private Sub ListServices_Click()

If Me.ListServices.ItemsSelected.Count = 0 Then
Exit Sub
Else
Me.frmServicesSub.SourceObject = "frmServicesSub"
Me.frmServicesSub.Form.Filter = "[ServiceID] = " & Me.ListServices.Column(0)
Me.frmServicesSub.Form.FilterOn = True
End If
End Sub

The List Box Prop. are as follow:
Row Source Type: Table/Query
Row Source: whatever the SQL code will insert here.


I have used .ItemsSelected.Count = 0 in other form before without any
problem, but in this specific scenario it is not cooperating with me. It
appear like the count is always 0.

Any idea how to solve this problem?
 
K

Klatuu

The ItemsSelected property is only used for Multi Select list boxes. If it
is not a Multi Select list box, it will not work.
--
Dave Hargis, Microsoft Access MVP


Silvio said:
Klatuu, the list only has between 0-5 items when populate and right now I
only have 10 records in my DB.
In debug mode shows I get itemsselected.count = 0 even though and I did
click on an item from the list, therefore the count should be = 1
The problem with ListCount is that it always returns a count of = 1 as
minimum. It appears that the List Box always has an empty item in it, and
that item is counted by the the ListCount function even if is null.




Klatuu said:
It is probably running. Have you run it in debug mode to see what happens.
What you are testing for here:

If Me.ListServices.ItemsSelected.Count = 0 Then

Is whether or not any items in the last have been selected by the use, not
whether there are any items in the list. If that is what you want, then the
test should be:

If Me.ListServices.ListCount = 0 Then

--
Dave Hargis, Microsoft Access MVP


Silvio said:
I have a List Box populated by an SQL statement based on another combo box
AfterUpdate event (Me.ListServices.RowSource = "SELECT tblServices.ServiceID,
tblServices.DateIn FROM tblAdoptions INNER JOIN tblServices ON
tblAdoptions.AdoptID = tblServices.Adopt_ID WHERE
(((tblAdoptions.Volunteer_ID)=[Forms]![frmServicesToClose]![VolunteerID]));
".

The list is populated with the correct items. So far, no problem.

I then run a code when clicking on an item in the list (on Click event). Of
course, if the list is empty then the code should not run. The problem is
that even when there are items in the list box the code does not run.


Private Sub ListServices_Click()

If Me.ListServices.ItemsSelected.Count = 0 Then
Exit Sub
Else
Me.frmServicesSub.SourceObject = "frmServicesSub"
Me.frmServicesSub.Form.Filter = "[ServiceID] = " & Me.ListServices.Column(0)
Me.frmServicesSub.Form.FilterOn = True
End If
End Sub

The List Box Prop. are as follow:
Row Source Type: Table/Query
Row Source: whatever the SQL code will insert here.


I have used .ItemsSelected.Count = 0 in other form before without any
problem, but in this specific scenario it is not cooperating with me. It
appear like the count is always 0.

Any idea how to solve this problem?
 
S

Silvio

My list will allow only one selection. Any idea why the blank item in list is
counted when there is no item in the list?

Klatuu said:
The ItemsSelected property is only used for Multi Select list boxes. If it
is not a Multi Select list box, it will not work.
--
Dave Hargis, Microsoft Access MVP


Silvio said:
Klatuu, the list only has between 0-5 items when populate and right now I
only have 10 records in my DB.
In debug mode shows I get itemsselected.count = 0 even though and I did
click on an item from the list, therefore the count should be = 1
The problem with ListCount is that it always returns a count of = 1 as
minimum. It appears that the List Box always has an empty item in it, and
that item is counted by the the ListCount function even if is null.




Klatuu said:
It is probably running. Have you run it in debug mode to see what happens.
What you are testing for here:

If Me.ListServices.ItemsSelected.Count = 0 Then

Is whether or not any items in the last have been selected by the use, not
whether there are any items in the list. If that is what you want, then the
test should be:

If Me.ListServices.ListCount = 0 Then

--
Dave Hargis, Microsoft Access MVP


:

I have a List Box populated by an SQL statement based on another combo box
AfterUpdate event (Me.ListServices.RowSource = "SELECT tblServices.ServiceID,
tblServices.DateIn FROM tblAdoptions INNER JOIN tblServices ON
tblAdoptions.AdoptID = tblServices.Adopt_ID WHERE
(((tblAdoptions.Volunteer_ID)=[Forms]![frmServicesToClose]![VolunteerID]));
".

The list is populated with the correct items. So far, no problem.

I then run a code when clicking on an item in the list (on Click event). Of
course, if the list is empty then the code should not run. The problem is
that even when there are items in the list box the code does not run.


Private Sub ListServices_Click()

If Me.ListServices.ItemsSelected.Count = 0 Then
Exit Sub
Else
Me.frmServicesSub.SourceObject = "frmServicesSub"
Me.frmServicesSub.Form.Filter = "[ServiceID] = " & Me.ListServices.Column(0)
Me.frmServicesSub.Form.FilterOn = True
End If
End Sub

The List Box Prop. are as follow:
Row Source Type: Table/Query
Row Source: whatever the SQL code will insert here.


I have used .ItemsSelected.Count = 0 in other form before without any
problem, but in this specific scenario it is not cooperating with me. It
appear like the count is always 0.

Any idea how to solve this problem?
 
D

Douglas J. Steele

Works fine for me, Dave...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
The ItemsSelected property is only used for Multi Select list boxes. If
it
is not a Multi Select list box, it will not work.
--
Dave Hargis, Microsoft Access MVP


Silvio said:
Klatuu, the list only has between 0-5 items when populate and right now I
only have 10 records in my DB.
In debug mode shows I get itemsselected.count = 0 even though and I did
click on an item from the list, therefore the count should be = 1
The problem with ListCount is that it always returns a count of = 1 as
minimum. It appears that the List Box always has an empty item in it, and
that item is counted by the the ListCount function even if is null.




Klatuu said:
It is probably running. Have you run it in debug mode to see what
happens.
What you are testing for here:

If Me.ListServices.ItemsSelected.Count = 0 Then

Is whether or not any items in the last have been selected by the use,
not
whether there are any items in the list. If that is what you want,
then the
test should be:

If Me.ListServices.ListCount = 0 Then

--
Dave Hargis, Microsoft Access MVP


:

I have a List Box populated by an SQL statement based on another
combo box
AfterUpdate event (Me.ListServices.RowSource = "SELECT
tblServices.ServiceID,
tblServices.DateIn FROM tblAdoptions INNER JOIN tblServices ON
tblAdoptions.AdoptID = tblServices.Adopt_ID WHERE
(((tblAdoptions.Volunteer_ID)=[Forms]![frmServicesToClose]![VolunteerID]));
".

The list is populated with the correct items. So far, no problem.

I then run a code when clicking on an item in the list (on Click
event). Of
course, if the list is empty then the code should not run. The
problem is
that even when there are items in the list box the code does not run.


Private Sub ListServices_Click()

If Me.ListServices.ItemsSelected.Count = 0 Then
Exit Sub
Else
Me.frmServicesSub.SourceObject = "frmServicesSub"
Me.frmServicesSub.Form.Filter = "[ServiceID] = " &
Me.ListServices.Column(0)
Me.frmServicesSub.Form.FilterOn = True
End If
End Sub

The List Box Prop. are as follow:
Row Source Type: Table/Query
Row Source: whatever the SQL code will insert here.


I have used .ItemsSelected.Count = 0 in other form before without any
problem, but in this specific scenario it is not cooperating with me.
It
appear like the count is always 0.

Any idea how to solve this problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top