Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 01-14-2019, 02:01 AM   #1
George-Bowyer
Newly Registered User
 
Join Date: Dec 2012
Posts: 124
Thanks: 55
Thanked 1 Time in 1 Post
George-Bowyer is on a distinguished road
Set False works, Set True doesn't???

Hello,

I've been using this code to uncheck all items in a list box for ages (can't remember where I got it from - somewhere here, probably) - and it works fine.


Code:
    Dim varItm As Variant

    With lstWhatever

        For Each varItm In .ItemsSelected
            .Selected(varItm) = False
        Next varItm

    End With
I just tried using it to check all of the boxes, which I assumed would just require changing "False" to "True", but bizarrely, the button does nothing.


Can anyone please explain this?

Thanks,

George


Last edited by George-Bowyer; 01-14-2019 at 04:41 AM. Reason: Added tags
George-Bowyer is offline   Reply With Quote
Old 01-14-2019, 02:09 AM   #2
June7
Newly Registered User
 
June7's Avatar
 
Join Date: Mar 2014
Posts: 1,653
Thanks: 0
Thanked 405 Times in 402 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: Set False works, Set True doesn't???

The code is only cycling through items that have been selected. They are already 'True'. If no items in listbox have been selected then there is nothing for the code to act on.

But what do you mean by 'check all of the boxes'? Exactly what 'boxes' are checked? A listbox doesn't have any place to enter a 'check'.
__________________
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
June7 is offline   Reply With Quote
Old 01-14-2019, 02:24 AM   #3
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 6,221
Thanks: 147
Thanked 1,675 Times in 1,647 Posts
Minty is a jewel in the rough Minty is a jewel in the rough Minty is a jewel in the rough
Re: Set False works, Set True doesn't???

There is an function below that you can call to do this on any list, courtesy or Allen Browne;

Code:
Public Function SelectAll(lst As ListBox) As Boolean
    On Error GoTo Err_Handler
    'Purpose:   Select all items in the multi-select list box.
    'Return:    True if successful
    'Author:    Allen Browne. http://allenbrowne.com  June, 2006.
    Dim lngRow As Long

    If lst.MultiSelect Then
        For lngRow = 0 To lst.ListCount - 1
            lst.Selected(lngRow) = True
        Next
        SelectAll = True
    End If

Exit_Handler:
    Exit Function

Err_Handler:
    Call LogError(Err.Number, Err.Description, "SelectAll()")
    Resume Exit_Handler
End Function

__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
The Following User Says Thank You to Minty For This Useful Post:
George-Bowyer (01-14-2019)
Old 01-14-2019, 04:44 AM   #4
George-Bowyer
Newly Registered User
 
Join Date: Dec 2012
Posts: 124
Thanks: 55
Thanked 1 Time in 1 Post
George-Bowyer is on a distinguished road
Re: Set False works, Set True doesn't???

Quote:
Originally Posted by Minty View Post
There is an function below that you can call to do this on any list, courtesy or Allen Browne;

Code:
Public Function SelectAll(lst As ListBox) As Boolean
    On Error GoTo Err_Handler
    'Purpose:   Select all items in the multi-select list box.
    'Return:    True if successful
    'Author:    Allen Browne. http://allenbrowne.com  June, 2006.
    Dim lngRow As Long

    If lst.MultiSelect Then
        For lngRow = 0 To lst.ListCount - 1
            lst.Selected(lngRow) = True
        Next
        SelectAll = True
    End If

Exit_Handler:
    Exit Function

Err_Handler:
    Call LogError(Err.Number, Err.Description, "SelectAll()")
Resume Exit_Handler
End Function
Thanks. The above line in red throws a "sub not defined" error.

I presume that this is because Allen Browne assumes that one is using his
error handling code as well?
George-Bowyer is offline   Reply With Quote
Old 01-14-2019, 05:48 AM   #5
June7
Newly Registered User
 
June7's Avatar
 
Join Date: Mar 2014
Posts: 1,653
Thanks: 0
Thanked 405 Times in 402 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: Set False works, Set True doesn't???

Yes, so change it to:

MsgBox Err.Number & " : " & Err.Description & " : " & "SelectAll()"

__________________
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
June7 is offline   Reply With Quote
The Following User Says Thank You to June7 For This Useful Post:
George-Bowyer (01-14-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Show either True, False or both True and False in query Turvoll Queries 5 11-24-2011 02:14 PM
Do Locked property works beyond True/False? prabha_friend Modules & VBA 1 02-16-2011 06:03 AM
Update query-If criteria true,value true else false in same query merc_slk Queries 3 01-11-2010 02:27 PM
displaying only true/false values that are true shrndegruv Reports 7 11-08-2004 09:55 AM
True/False Box ddrew Forms 4 04-02-2004 01:57 PM




All times are GMT -8. The time now is 05:02 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World