none
Button to Clear Data Entry Form RRS feed

  • Question

  • I have a form that is set to enter data instead of viewing records. My form will have three buttons (New, Submit, Close). I'm new at this so I thought I'd just throw some questions out there about how to make my buttons work. 

    New only needs to clear anything that's already been entered. Close only needs to close the form and not save anything or prompt the user to save. 

    Submit will do some error handling and such, and then it will save the entry to a table. It will also need to assign a unique ID. 

    I don't expect detailed answers to all of these, just an idea on how to do them. So for example, for the New button is there a macro that already clears my form? 

    Any newbie advice would be welcome.

    tod

    Monday, May 23, 2016 5:47 PM

Answers

All replies

  • Maybe not really a developers question but.

    Assuming your form is bound to a table, you should not "Clear" the data but move to a new record with an event procedure from the buttons onclick event

    docmd.GoToRecord acDataForm, "myForm",acNewRec

    Close will save and close.

    docmd.close

    if you want to clear enterd information press ESC

    Or use

    ME.Undo


    Brian, ProcessIT- Hawke`s Bay, New Zealand

    Monday, May 23, 2016 9:19 PM
  • Hi todtown,

    Here I think the suggestion given by the ProcessIT is an appropriate suggestion for your issue. This suggestion is able to solve your issue. so kindly check the suggestion given by the ProcessIT.

    if you think the suggestion given by the ProcessIT can solve your issue then please mark the suggestion given by ProcessIT as an Answer.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 24, 2016 2:20 AM
    Moderator
  • The code posted by ProcessIT is a good solution for a custom button.

    >>> is there a macro that already clears my form?

    For built-in functionality, familiarize yourself with the ribbon and with navigation options on your form,  The 'records' group on the Home tab on the default Access ribbon has New and Save buttons, and the navigation buttons at the bottom of the form allow you to move to prev/first/next/last/new records.

    >>> It will also need to assign a unique ID.

    Have you ruled out using an autonumber Primary Key for this?


    Miriam Bizup Access MVP

    Tuesday, May 24, 2016 9:55 AM
  • With a unbound form the code would along these lines:

    Dim ctrl As Control

    On Error Resume Next
    For each ctrl In Me.Controls
        ctrl = Null
    Next ctrl

    A more developed version would be to set the Tag property of those controls you wish to clear to ClearMe, in which case the code would be:

    Dim ctrl As Control

    For each ctrl In Me.Controls
        If ctrl.Tag = "ClearMe" Then
            ctrl = Null
        End If
    Next ctrl

    Ken Sheridan, Stafford, England

    Wednesday, May 25, 2016 4:40 PM