PC Review


Reply
Thread Tools Rate Thread

Disable a cmdButton when no selection in list

 
 
=?Utf-8?B?RGhlaW56ZTU3?=
Guest
Posts: n/a
 
      5th Apr 2006
I use a cmdButton to print reports filtered by a list box with multi select
set to "simple" (http://allenbrowne.com/ser-50.html).
How can I disable the cmdButton when there are no selections. (If there are
no selections it runs the report with the last filter saved with the report)

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFydGlu?=
Guest
Posts: n/a
 
      5th Apr 2006
In design view, make sure the cmdButton is disabled (and remember to save the
form with it still disabled - easy to forget after fiddling with the macros!).

Go to properties of the list box and use the builder button next to After
Update event. This event is triggered every time a selection/deselection in
the list made. The kind of code you could use is:

Private Sub ListBox_AfterUpdate()
If IsNull(ListBox) Then
cmdButton.Enabled = False
Else
cmdButton.Enabled = True
End If
End Sub


"Dheinze57" wrote:

> I use a cmdButton to print reports filtered by a list box with multi select
> set to "simple" (http://allenbrowne.com/ser-50.html).
> How can I disable the cmdButton when there are no selections. (If there are
> no selections it runs the report with the last filter saved with the report)
>

 
Reply With Quote
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      5th Apr 2006
I don't think that will work like you expect it to. I would suggest using
the ListCount property of the List box.

Private Sub ListBox_AfterUpdate()
Me.MyCommandButton.Enabled = Me.MyListBox.ListCount <> 0
End Sub

If No selections have been made, the ListCount will be 0 which will return
False; otherwise, it will return True.


"Martin" wrote:

> In design view, make sure the cmdButton is disabled (and remember to save the
> form with it still disabled - easy to forget after fiddling with the macros!).
>
> Go to properties of the list box and use the builder button next to After
> Update event. This event is triggered every time a selection/deselection in
> the list made. The kind of code you could use is:
>
> Private Sub ListBox_AfterUpdate()
> If IsNull(ListBox) Then
> cmdButton.Enabled = False
> Else
> cmdButton.Enabled = True
> End If
> End Sub
>
>
> "Dheinze57" wrote:
>
> > I use a cmdButton to print reports filtered by a list box with multi select
> > set to "simple" (http://allenbrowne.com/ser-50.html).
> > How can I disable the cmdButton when there are no selections. (If there are
> > no selections it runs the report with the last filter saved with the report)
> >

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      5th Apr 2006
Pardon me.

ListCount counts the number of items in the list. It doesn't tell you how
many (if any) have been selected.

ItemsSelected.Count will give you a count of the items that have been
selected with a multi-select listbox.

So, I believe you would have to use

Me.MyCommandButton.Enabled = Me.MyListBox.ItemsSelected.Count <> 0


"Klatuu" <(E-Mail Removed)> wrote in message
news:8EB2D4E6-AD95-4E53-B376-(E-Mail Removed)...
>I don't think that will work like you expect it to. I would suggest using
> the ListCount property of the List box.
>
> Private Sub ListBox_AfterUpdate()
> Me.MyCommandButton.Enabled = Me.MyListBox.ListCount <> 0
> End Sub
>
> If No selections have been made, the ListCount will be 0 which will return
> False; otherwise, it will return True.
>
>
> "Martin" wrote:
>
>> In design view, make sure the cmdButton is disabled (and remember to save
>> the
>> form with it still disabled - easy to forget after fiddling with the
>> macros!).
>>
>> Go to properties of the list box and use the builder button next to After
>> Update event. This event is triggered every time a selection/deselection
>> in
>> the list made. The kind of code you could use is:
>>
>> Private Sub ListBox_AfterUpdate()
>> If IsNull(ListBox) Then
>> cmdButton.Enabled = False
>> Else
>> cmdButton.Enabled = True
>> End If
>> End Sub
>>
>>
>> "Dheinze57" wrote:
>>
>> > I use a cmdButton to print reports filtered by a list box with multi
>> > select
>> > set to "simple" (http://allenbrowne.com/ser-50.html).
>> > How can I disable the cmdButton when there are no selections. (If there
>> > are
>> > no selections it runs the report with the last filter saved with the
>> > report)
>> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box list selection based on earlier selection by user MSA Microsoft Access Form Coding 2 27th Feb 2008 05:00 PM
Lock or disable form till cmdButton pressed =?Utf-8?B?Z2hpbGxpZTUxNTA=?= Microsoft Access Form Coding 9 8th May 2006 06:51 PM
Disable new records until cmdbutton is pressed =?Utf-8?B?S2luc3Rlcg==?= Microsoft Access Getting Started 0 24th Feb 2005 04:29 PM
Disable cmdButton if record doesn't exist Mike Revis Microsoft Access Getting Started 3 18th Jan 2005 05:17 AM
limit cell list selection based on the selection of another list =?Utf-8?B?bG9ycmFpbmU=?= Microsoft Excel Worksheet Functions 2 14th Dec 2004 08:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:06 PM.