Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  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 offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is your form bound to a Recordset and are all of the controls bound as well?

  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 offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    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?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did I lose you there?

  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 offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Me.UnDo will return all controls on the form back to what is saved in the Recordset.

  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 offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You lost me on that one. How about just don't Close the form? That's too easy right?

  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 offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    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

  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 offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That is usually done by deleting the record and starting with a new one.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are you ready to call this thread Solved? It is one of the Thread Tools.

  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, 12:29 PM
  2. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  3. Form/report command button code
    By max3 in forum Forms
    Replies: 1
    Last Post: 08-26-2009, 02:18 AM
  4. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 04:26 PM
  5. Search and Clear button
    By polk383 in forum Programming
    Replies: 1
    Last Post: 08-30-2006, 08: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
  •  
Other Forums: Microsoft Office Forums