Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21

    Clearing Sub Form

    Is there a way to clear a sub form of selections that I made from a previous report? The way it is now I have to go in to the sub form and manually click each item I had previously selected be for I can do a new report with different selections.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You are using a Yes/No field in table to allow selection of records? You want to just clear the checkbox for all records? VBA code:

    CurrentDb.Execute "UPDATE tablename SET fieldname=False"
    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
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    One way would be to put a command button on the sub-form to reset all the sub-form fields when clicked (using VBA).

    If the sub-form is bound to a table or query, you could just delete the entire record, and go to a new one.

    That is a bit of a misuse of a sub-form, though - could you not just put the selection criteria on the main form, in unbound controls?

    John

  4. #4
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    So if I create a command button and then copy and paste the above VBA to the OnClick event procedure, then that should work right?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try it and see. Use your table and field names.
    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
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    I don't know how to do that John, can you direct me? I created a command button, but I couldn't get it to work.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Select [Event Procedure] in the OnClick event property, click the ellipsis (...) to open VBA editor, type code.
    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.

  8. #8
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Is the form bound to a table or query, i.e. does it have a table/query as the recordsource?

    The code to clear (reset) the form would be something like this:

    for text fields:

    Me![Control1] = ""
    me![Control2] = ""
    etc.

    and for numeric fields:

    Me![Control3] = 0
    Me![Control] = 0
    etc.

    Replace Control1, Control2, .... with the actual control names on your form.

  9. #9
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    Yes it is tied to one table called "Sub Category"

  10. #10
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    Do I replace the "CurrentDb" with the name of the query or table?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    No, replace "tablename" and "fieldname" with your actual names.
    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.

  12. #12
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    Here is what I wrote, but does not work

    CurrentDb.Execute "UPDATE Sub Category SET Click=False"

    Should I put True or False in the criteria line of the table. Right now it says True.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Names with spaces and special characters/punctuation must be enclosed in []: [Sub Category]

    Advise to avoid those in naming convention (underscore is exception).

    Criteria should not be needed.
    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.

  14. #14
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    I hate to keep bother you, but I must be missing something, because it still doesn't clear the form.

    Here is my code - CurrentDb.Execute "UPDATE[Sub Category]SET[Check]=False"

    This was placed in the event procedure VBA area. When I click on the button I get an error. See attached imaged.

    Click image for larger version. 

Name:	screen shot.jpg 
Views:	6 
Size:	110.5 KB 
ID:	16907

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I advised no spaces in names, sql statements need spaces to define distinct words.

    CurrentDb.Execute "UPDATE [Sub Category] SET [Check]=False"
    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. Is clearing a form the same as adding a new record?
    By Access_Novice in forum Forms
    Replies: 2
    Last Post: 12-04-2013, 08:15 PM
  2. Clearing a search box on a form
    By pbouk in forum Forms
    Replies: 13
    Last Post: 02-06-2013, 04:54 PM
  3. Clearing a Form
    By dabatman in forum Forms
    Replies: 4
    Last Post: 01-20-2012, 11:51 AM
  4. Error when clearing form
    By turbo910 in forum Forms
    Replies: 11
    Last Post: 11-26-2009, 11:03 AM
  5. clearing a form
    By macsterling in forum Forms
    Replies: 0
    Last Post: 07-31-2008, 10:38 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