VBA to Save a Record and Close Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DesertKat
    New Member
    • Apr 2014
    • 1

    VBA to Save a Record and Close Form

    To promote data integrity, want to limit end user to entering 1 record at a time.

    After end-user has entered data into Form need to:
    -Save the Record
    -Close the Form
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    There are a few different ways to save a record but the way that I like the best is to use the RunCommand:
    Code:
    DoCmd.RunCommand acCmdSaveRecord
    To close a form you use the DoCmd.Close command.
    Code:
    'To be run from the form being closed
    DoCmd.Close acForm, Me.Name
    
    'To be run from another form
    DoCmd.Close acForm, "YourFormName"

    Comment

    • sophannaly
      New Member
      • Mar 2014
      • 67

      #3
      Hi Seth,

      If user input or edit a text field value then he didn't move his mouse or click on other field, then this new value won't save to table. Will DoCmd.RunComman d acCmdSaveRecord push all these data to save it in table?

      Sophanna

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        Assuming that the textbox is bound to an editable field, then just closing the form would save it unless you have code that blocks the saving of the data. So you could just put my first form closing code in your textbox's After_Update event. The data would be saved automatically without any code required.

        Comment

        Working...