Results 1 to 4 of 4
  1. #1
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727

    The VBA Save Command

    I been using a method for saving for a long time because I have always had trouble with using the Docmd.Save command. The process I have created or should I say workaround I have used all this time is that I have a save button that the user clicks on, and what this button actually does is go to the previous record and back to the current record forces the record to be saved. Then to create the image of a regular save for the user, while that is happening, I also have code in the before update event of the form that will ask the user if they want to save the record? If they click yes, then it will save (go to previous record, then back to current record). If they click no, it will undo.



    So its been working ok for a really long time but its not perfect. The annoying part is that if you click no, it will undo all the changes you made to the record. Sometimes you may click the save button and then realize that you want to add something else to the record and click no because you don't want to save yet, and there goes your record. The whole reason why I had to create such a workaround is because I could never get the save command to really work the way I thought it should. Does anyone have code or suggestions on how to have a normal save process? I just want something similar to what happens in microsoft word.

    You make changes, you click the save button, it saves.
    You make changes, you try to close the document, or in some cases in Access (you try to navigate to another form or record), it prompts to ask if you want to save the changes, you click yes, it saves, you click no, it undoes the changes.

    Does anyone have something like that?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Maybe you want 3 options:

    Yes, save and return to record.

    No, don't save, cancel update and return to record but don't undo any thing.

    Cancel, don't save and don't retain edits (undo all).

    The prompt can have Yes/No/Cancel buttons.
    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
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Do you have an example code for using 3 options? Yes/No/Cancel?

    I could never get it to work with this code:

    If MsgBox("Save Record?", vbYesNoCancel, "Save Record") = vbYes Then
    DoCmd.RunCommand acCmdSaveRecord
    ElseIf MsgBox("Save Record?", vbYesNoCancel, "Save Record") = vbNo Then
    DoCmd.RunCommand acCmdUndo
    Else
    Me.txtCustName.SetFocus
    End If

    I was thinking of coding this behind a button that takes you to another record within a form. Got any ideas how to get this to work? This code structure works if I used vbYesNo but once I add the cancel to the mix, it doesn't work. Here is how I used the vbYesNo:

    If MsgBox("Save Record?", vbYesNo, "Save Record") = vbYes Then
    DoCmd.Save
    Else
    DoCmd.RunCommand acCmdUndo
    End If

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    With 3 options, usually need a variable for the MsgBox response. Example:

    intResponse = MsgBox("Save Record?", vbYesNoCancel, "Save Record")
    If intResponse = vbCancel Then
    ...
    ElseIf intResponse = vbNo Then
    ...
    Else
    ...
    End If

    Or try Select Case structure:

    Select Case MsgBox("Save Record?", vbYesNoCancel, "Save Record")
    Case vbCancel
    ...
    Case vbNo
    ...
    Case vbYes
    ...
    End Select
    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. Replies: 5
    Last Post: 02-03-2014, 03:06 AM
  2. Replies: 15
    Last Post: 01-28-2014, 12:20 PM
  3. Help Me! Save Record Command Button issue
    By gszdwml in forum Programming
    Replies: 1
    Last Post: 04-24-2012, 09:53 AM
  4. Replies: 9
    Last Post: 01-20-2011, 02:22 PM
  5. Replies: 1
    Last Post: 04-22-2010, 04:54 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