Results 1 to 6 of 6
  1. #1
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253

    Trouble clearing records on a form


    I am trying to write code in a subform to clear all textboxes and checkboxes on a form before they are written to the table. My subform has all the navigation buttons for multiple forms. I want to make a clear record button for if someone makes a mistake while filling in the data. I am wanting the clear button to work on the multiple forms. I was thinking of using the control tags but i dont know how to clear checkboxes using the control tags. The forms have different amounts of textboxes and checkboxes. What would be the best way to accomplish what i am trying to do? Thank you in advance. --Walker

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    After you've checked the tag property you can use Select/Case on the ControlType of the current control, and do something different (set to 0) for combos.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    not at all clear to me why you would want to do this but if you want one bit of code to work for every form then something like this function placed in a general module might do what you want

    Code:
    function formCleared(frm as form) as boolean
    dim ctl as control
    
    on error goto errctrl
    
        for each ctl in frm.controls
            if ctl.controltype =acTextBox then ctl=null
        next ctl
    
        formCleared=true
        exit function
    
    errctrl:
       msgbox "err & ": " & err.description & " in " & frm.name
       formCleared=false
    
    end function
    you would call it from a form with something like

    if formCleared(me) then donextthing

  4. #4
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I am wanting to make a one click way for the user to clear the data they put into the form. At current time the multiple forms are bound forms. Maybe this would be a better question. Is it best practice to make a recordset with an unbound form for data entry forms? If my thinking here is correct then i could just clear the recordset before the submit/save button was clicked. Would this be a better approach?

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    why not just set the form data entry property to yes?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by NightWalker View Post
    Is it best practice to make a recordset with an unbound form for data entry forms? If my thinking here is correct then i could just clear the recordset before the submit/save button was clicked. Would this be a better approach?
    As to this, while I'm not above using an unbound form, probably 95% of the forms I've built are bound. I think the prevailing opinion is that it's easiest to let Access do the heavy lifting.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Clearing all controls on a form
    By streub in forum Forms
    Replies: 9
    Last Post: 02-19-2018, 06:25 PM
  2. Clearing Sub Form
    By eagle670 in forum Forms
    Replies: 19
    Last Post: 06-23-2014, 02:31 PM
  3. Clearing a search box on a form
    By pbouk in forum Forms
    Replies: 13
    Last Post: 02-06-2013, 04:54 PM
  4. Clearing a Form
    By dabatman in forum Forms
    Replies: 4
    Last Post: 01-20-2012, 11:51 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