Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    h_aaron is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    10

    Clear combo box selections from form


    Good afternoon

    Newbie warning - I do not know how to program in Access. But I've developed a database that uses a form to access a query to display a report. What I'd like to do is have a button that I can clear the selections in the form. I created a "refresh" button but I get the error listed below. I've also included a screenshot of my form. Thanks for any help you can provide.

    "Command or Action 'refresh' isn't available now. *You may be in read-only database or an unconverted database from an earlier version or Microsoft access. * The type of object the action appies to isn't currently selected or isn't in the active view. Use only those commands and macro actions that are currently available for this database."

    Click image for larger version. 

Name:	ScreenShot.jpg 
Views:	36 
Size:	176.2 KB 
ID:	34256

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Assume those are UNBOUND comboboxes used to input filter criteria.

    Code behind button would set each combobox to Null or empty string (I use Null).

    Why 4 comboboxes for same criteria?

    Options to refresh the objects already open:

    1. Click 'Refresh All' on the ribbon

    2. VBA code: CommandBars.ExecuteMso "DataRefreshAll"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I would also assume that the Form itself is Unbound

    Two things:

    First...if a Form has no Record Source there's nothing to 'refresh'...hence the error.

    Second...'Refresh' is not intended to 'clear' the Controls on a Form.

    Quote Originally Posted by AccessHelp

    The Refresh method immediately updates the records in the underlying record source for a specified form or datasheet to reflect changes made to the data by you and other users in a multiuser environment
    .
    As June7 said...merely set the Combobox Controls to Null.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    h_aaron is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    10
    To answer your questions -
    1) yes, I 'believe' the form is unbound.
    2) multiple Combo Boxes so that the user may select up to 4 buildings to review at a time. (I'm most likely going to add a Select All option)

    I do like the Control to Null suggestion - however, as I mentioned, I'm a newb and have no idea how to do so. Would one of you mind providing me with instructions on how to do so? I do everything in Design View - sorry for being so difficult.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Me.comboboxname = Null

    Post your code if you need more help with it.

    Are you using a dynamic parameterized query? Post the query SQL.

    Review: http://allenbrowne.com/ser-62.html

    Only 4 buildings? Could use a listbox to allow more. Allen Browne has sample code for that as well. A link is within the other.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    h_aaron is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    10
    Hi June7
    I really hate to sound like I don't know what I'm doing - oh wait, I don't - but how do I access the code? I have never even seen the code. Can you tell me what I need to do to see the code?

    Thanks.

    I have over 40 buildings that I'm inventorying. Usually, we only review a few areas at a time - hence the 4 combobox. But, I'm always interested in how to do things better.

  7. #7
    h_aaron is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    10
    Ok, I finally figured out how to see the code - duh, "View Code" should have been an indicator. Below is what that showed me. Would you please tell me how I would insert the Null in here so it will reset all four combo boxes? Thx!!!



    Option Compare Database


    Private Sub cboBldgName1_Click()


    End Sub


    Private Sub Command14_Click()
    End Sub

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Since you state you are a newbie (we all were at one point ), maybe you would like a review of your dB?
    You only show 2 forms, but there are 8 tables?

    If you decide to post the dB, make a copy, delete all but 1 or 2 buildings, change sensitive data (address or building name), do a "Compact & Repair", then Zip it.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    code editor is alt+F11 or if I recall, Ctrl+G (I only use the former)
    but you are probably using macros? Can't see any in your navigation pane, so am guessing based on your comments. Sometimes we tend to forget that some very novice types do not know code at all, and mostly, we don't use macros so are sketchy on them.

    But, I'm always interested in how to do things better.
    A control for each option of the same type of thing isn't the way to go. List boxes are better than combo boxes in some ways, but these ways involve coding that might be too much for you at this point. A combo is simpler but you can't use multi select in it. Basically, anything that doesn't require you to modify a form design to accommodate a new choice is the proper approach, so this would exclude a checkbox for each option as well.

    This sort of advice is well intentioned, but sometimes the complex is too much for beginners, and possibly we all are guilty of doing the very things we say not to do if we think back far enough - unless someone was just a wizard at this stuff from day one. I know I wasn't.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    h_aaron is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    10
    Oh My Goodness ssanfu - That would be awesome. And, Micron - you nailed it - macros & no code. But, I want to learn. I'll attach a zipped copy of my dB with sensitive data removed. Thanks to all of you!!!


    ,

  11. #11
    h_aaron is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    10
    Oh My Goodness ssanfu - That would be awesome. And, Micron - you nailed it - macros & no code. But, I want to learn. I was planning to attach a zipped copy but I keep getting an error message stating the file can't be uploaded. Any idea if I'm not allowed to attach zips? Thanks to all of you!!!


    ,

  12. #12
    h_aaron is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    10
    Argh. I can't get the file smaller than 5 MB. So close...

  13. #13
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sharing via Box, DropBox, One Drive?????

  14. #14
    h_aaron is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    10
    Durr.... Thanks for all your patience Steve - Here you go https://www.dropbox.com/s/448mn2jjbk...gmt.accdb?dl=0

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Just type it.

    Private Sub Command14_Click()
    Me.comboboxname = Null
    End Sub

    But use your actual combobox name. You will need a line for each combobox.

    Me. is shorthand alias for the form or report the code is behind.

    Advise you name your button something more meaningful (as you should for all controls, especially when referenced in code) than Command15, like btnClear. Then the procedure declaration would be:

    Private Sub btnClear_Click()

    If you have no programming background in any language, recommend you work through some tutorials. Knowledge of basic programming concepts is transferable. Then need to learn VBA language - more tutorials. Review https://access-programmers.co.uk/for...d.php?t=159756
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 01-26-2018, 05:01 PM
  2. Replies: 7
    Last Post: 01-30-2015, 03:27 PM
  3. Replies: 2
    Last Post: 10-03-2012, 02:58 AM
  4. Clear selections from a List Box?
    By Dreams2Fly in forum Forms
    Replies: 3
    Last Post: 03-28-2011, 02:25 PM
  5. Replies: 1
    Last Post: 03-02-2009, 11:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums