Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Command button code to clear form

  1. #1
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46

    Command button code to clear form

    I would like to have a command buttom on my form and on click clear all entries. Please help with the code?

  2. #2
    RuralGuy's Avatar
    RuralGuy is online now Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,888
    Is your form bound to a Recordset and are all of the controls bound as well?
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  3. #3
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46
    It is bound to a table/guery as well as controls bound to the same.

  4. #4
    RuralGuy's Avatar
    RuralGuy is online now Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,888
    Are you just tryine to get to a *new* blank record or are you trying to wipe out and existing record? You do understand the if you are on an existing record and clear a bound control, that is also trying to clear the field in the recordset as well right?
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  5. #5
    RuralGuy's Avatar
    RuralGuy is online now Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,888
    Did I lose you there?
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  6. #6
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46
    No I'm not lost but in and out today. Sorry for the delay geting back.

    I looking to have the command button just clear the info I just typed in and did not save and still have the form stay open.

  7. #7
    RuralGuy's Avatar
    RuralGuy is online now Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,888
    Me.UnDo will return all controls on the form back to what is saved in the Recordset.
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  8. #8
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46
    Thank You.

    I am now working with a MS template and the code I found is as follows:

    Private Sub cmdCancel_Click()
    ' User wants to bail
    ' If an edit in progress..
    If (Me.Dirty = True) Then
    ' Clear it
    Me.Undo
    End If
    ' And close me
    DoCmd.Close acForm, Me.Name
    End Sub

    I think I have a simple question:
    How can I stop the form from closing but still clear data I just inputed so I can enter new data?

  9. #9
    RuralGuy's Avatar
    RuralGuy is online now Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,888
    You lost me on that one. How about just don't Close the form? That's too easy right?
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  10. #10
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46
    I agree. I don't want to close the form.


    The code I have from the template closes the form. I am not familiar with code and was asking how to modify this code or write new code to clear the opened form and not close it so I can start new data input with cleared form.

  11. #11
    RuralGuy's Avatar
    RuralGuy is online now Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,888
    Just comment out the second to last line:
    DoCmd.Close acForm, Me.Name
    ...just add a ' at the beginning of the line like:
    ' DoCmd.Close acForm, Me.Name
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  12. #12
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46
    Simple, thanks for the info change. I thought I did that a couple of days ago. I guess I deleted something wrong.

    When I got the code to work I noticed it truely does UnDo the data inputted but data in a past saved record will not be cleared. Is there another command to clear the data and update that record? Or is this not recommended?

  13. #13
    RuralGuy's Avatar
    RuralGuy is online now Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,888
    That is usually done by deleting the record and starting with a new one.
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  14. #14
    RuralGuy's Avatar
    RuralGuy is online now Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,888
    Are you ready to call this thread Solved? It is one of the Thread Tools.
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  15. #15
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46
    We are done and I thank you for your help.

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

Similar Threads

  1. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 11:29 AM
  2. Replies: 1
    Last Post: 07-27-2010, 01:27 PM
  3. Form/report command button code
    By max3 in forum Forms
    Replies: 1
    Last Post: 08-26-2009, 01:18 AM
  4. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 03:26 PM
  5. Search and Clear button
    By polk383 in forum Programming
    Replies: 1
    Last Post: 08-30-2006, 07:51 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
  •  
Tech Forums: Microsoft Office Forums