Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Clearing a listbox (2002)

    Hi,

    I have a form that opens to the record that is selected from a list. When the list does not have a record selected it opens to a new record which is what I need it to do. this is all done via query that the form is bound to. My problem is or my question is, is there a way to clear the list or make it a null choice? In otherwords, make the hightlighted go away so there is no choice in the list? I've tried various code but nothing has cleared it.

    Thanks,
    Leesha

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Clearing a listbox (2002)

    I'm not sure I fully understand your question.

    If you want to remove all entries from the list box, set its row source to an empty string, for example
    <code>
    Me.lstNames.RowSource = ""
    </code>
    where lstNames is the list box. Or do you just want to remove the selected item from the list box? Or just unselect the selected item?

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Clearing a listbox (2002)

    Hi Hans!

    I just want to remove the selected item from the listbox.

    Thanks,
    Leesha

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Clearing a listbox (2002)

    If the row source of the list box is a table or query, removing an item means that you must delete the record from the table or modify the query so that the record is no longer returned. Do you really want to do that, and why?

  5. #5
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Clearing a listbox (2002)

    I don't actually want to remove the record, just the reference to it. Basically what I'm trying to achieve is a list box that hasn't had a selection made yet (nothing highlighted).

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Clearing a listbox (2002)

    If I understand you correctly, you want to unselect the selected item. You can do that using the following instruction:
    <code>
    Me.lstNames.Selected(Me.lstNames.ListIndex) = False
    </code>
    where lstNames is the name of the list box.

  7. #7
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Clearing a listbox (2002)

    Hi Hans,

    I tried the code without luck. I'm attaching a stripped down version of the DB. When you click the button with the white paper icon it should clear th list but doesn't seem to. What am I missing?

    Thanks,
    Leesha

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Clearing a listbox (2002)

    Leesha,

    I've been trying to find out what exactly you want - each time it seems to be something different:
    > clear the list
    > make it a null choice
    > make the hightlighted go away
    > remove the selected item from the listbox
    > a list box that hasn't had a selection made yet (nothing highlighted)
    > clear th list
    Unless you can explain clearly and without ambiguity what you want to accomplish, it is impossible to help you.

    (And why don't you have Option Explicit at the top of the module? I thought we'd been through that extensively three years ago!)

  9. #9
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Clearing a listbox (2002)

    Leesa

    If you put Me.lstPatient = Null
    behind your button does that do what you want?
    Regards
    John



  10. #10
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Clearing a listbox (2002)

    OUCH! I almost hesitate to write back but I did want to apologize for any confusion. I simply want the list to clear so that there is no choice in it or hightlighted area. My desire has been the same all along but my trouble is trying to explain it.

    Re Option explicit, I've been much better at using it but honestly sometimes I forget to put it in. It would be easier if the database automatically put it in each time I start a new one. This is an old database (pre-Hans) that I'm doing some revisions to and I guess I didn't think to check all the forms. WOW you've got a wonderful memory to remember back 3 years. I guess I've flunked this course.

    <img src=/S/bash.gif border=0 alt=bash width=35 height=39>
    Leesha

  11. #11
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Clearing a listbox (2002)

    Hi John,

    That gave me an error - "Invalid use of null"

    Thanks,
    Leesah

  12. #12
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Clearing a listbox (2002)

    NDERFU:Hi John,

    That gave me an error - "Invalid use of null"

    Thanks,
    Leesah

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Clearing a listbox (2002)

    If you select Tools | Options in the Visual Basic Editor and tick the check box "Require Variable Declaration" in the Editor tab, Option Explicit will automatically be placed at the top of all new modules. You'll still have to add it manually to modules that already existed before you turned on "Require Variable Declaration".

  14. #14
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Clearing a listbox (2002)

    Are you working with the the db that you posted? or your original.

    Me.lstPatient = Null
    works Ok for me in what you posted.

    Re option explicit

    If you go into the VBA editor, and choose Tools Options..Editor, and puit a tick in "Require variable declaration" then Option Explicit will be put in automatically.
    Regards
    John



  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Clearing a listbox (2002)

    Try the suggestion from my first reply. In your form, the line would be
    <code>
    Me.lstPatient.RowSource = ""</code>

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •