Results 1 to 6 of 6
  1. #1
    jmitchelldueck is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    51

    Saving Records

    Hi,

    I'm currently using a button with VBA code On Click event to save a record.

    My code is this:




    Code:
    Private Sub Command117_Click()
    DoCmd.Save
    End Sub

    Is there a better way to do this with code? I found the DoCmd on Google and guessed at Save, and it works, but I would like to improve my knowledge.

    Thanks,
    jmd

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    That code does not save record. It is to save form or report object with design edits.

    A record is committed to table when move to another record, close table/query/form, or run code.

    DoCmd.RunCommand acCmdSaveRecord
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    If you need to bring up a blanked form for new data entry you could also do

    DoCmd.GoToRecord , , acNewRec

  4. #4
    jmitchelldueck is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    51
    So if I have a multiple record form, moving from record to record will automatically save any changes I made in the previous? Meaning the Save button is only useful for the last record I edit.

  5. #5
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    If you have a multiple record form (like if you were browsing through & updating records) moving from record to record will save any changes made on the previous record. If you want to save the record and then let's say close the form; June's code is what you can use followed by a close command:

    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close

    If you have lots of data you want to enter consecutively (like at the end of the data you have a bunch of data you need to enter) then use:

    DoCmd.GoToRecord , , acNewRec

    and it will bring up a new form for additional entry, while saving the data you just entered. The current .Save function you have now does not save a record, it saves design changes.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    As noted, moving to another record or closing form will commit record to table. The acCmdSaveRecord command is not need in those cases.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Form not saving records
    By jree3000 in forum Forms
    Replies: 9
    Last Post: 06-17-2014, 07:01 PM
  2. Lock individual records after saving
    By DOC666 in forum Access
    Replies: 3
    Last Post: 05-05-2014, 02:54 PM
  3. saving records on a form
    By trailerdoctor in forum Forms
    Replies: 1
    Last Post: 04-15-2013, 11:02 PM
  4. Saving Multiple Records at once
    By EvanRosenlieb in forum Access
    Replies: 5
    Last Post: 10-18-2011, 12:39 PM
  5. Saving records when a button is pushed
    By LAazsx in forum Programming
    Replies: 1
    Last Post: 11-28-2010, 10:06 PM

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