save or cancel

PaulJK

Registered User.
Local time
Today, 07:35
Joined
Jul 4, 2002
Messages
60
My users have asked for a control which prompts them on whether they want to save or cancel entries made in forms.

I am still getting to grips with code and presume I would need something in the 'BeforeUpdate' event? Does anyone have some code they can post which has worked for them?

I think I read somewhere in one of the topics the save/cancel options already exist in Access but are hidden. Can these be unhidden if this is so?

One concern is that the 'Supplier' form which is used to record data has some additional forms (for data entry) linked to it by supplierID. At the moment you can open these up once the 'Supplier' form has a supplierID & enter data. The original Supplier form still has some mandatory information required. If this is not entered & the user closes data in the other forms could be held. What I am getting at in a round about way is to have some controls built into the command buttons linking the forms not allowing the linked forms to open until the supplier form has been saved (which could only occur if the manadatory information is entered). If there is code it would help if you could post and confirm where it should be entered.

Thanks in advance.
 
Search

If you do a search on this forum for "save cancel". There is loads of code available.

Hope this helps
 
Thanks for the reply.

I had already done a search and obtained a few examples which I have been testing.

My concern is the potential issue in my third paragraph. A user can only move to a linked form once the primary form has been saved. They get an option to save or cancel. If save is selected the linked form opens. If cancel the primary form closed.
 
Got some code working to provide a save/cancel prompt. AS soon as a form is closed or moves onto another record the prompt appears.

Still have a problem whereby a primary form (supplier) can be completed but not saved, a command opening a linked form is selected & imformation on this form is completed and saved when the form is closed. The user then has the primary form available & selects not to save this. This means a supplierId is created and recorded against the linked form item but that supplier does not actually exist in the suppliers table!

Unlikely I know, but I am sure some users will do this.

I presume I would need to place my save/cancel code on the command buttons. I have tried this but cannot get anything to work. Where should I place it. Does it have to merge with the code opening the linked form?

If someone can point me in the right direction, I would be grateful.
 
Sorted, i hope. Placed an additional Save command in the OnClick event.

Seems to work ok apart from if the user goes straight to the command button (ie does not enter any information which provides a supplierid) & then selects to cancel. Syntax error with supplier id occurs, but I guess I can live with this.
 
Not sure if this helps your situation for I am not exactly sure what is going on with your form but this is
what I use for a custom save command...

Code:
Private Sub bSave_Click()
On Error GoTo Err_bSave_Click
    
    Dim cMessage As String
    Dim nArguments As Integer
    Dim cTitle As String
    
    Beep
    cMessage = "Do you want to save your changes to the current record?" & vbCrLf & vbLf
    cMessage = cMessage & "  Yes:         Saves Changes" & vbCrLf
    cMessage = cMessage & "  No:          Does NOT Save Changes" & vbCrLf
    cMessage = cMessage & "  Cancel:    Resets (Undo) Changes" & vbCrLf
    
    nArguments = vbYesNoCancel + vbQuestion
    
    cTitle = "Save Current Record?"
    
    Select Case MessagePrompt(cMessage, nArguments, cTitle)
        Case vbYes: 'Save the changes
            DoCmd.RunCommand acCmdSaveRecord
    
        Case vbNo: 'Dont save or undo
            'Do nothing
    
        Case vbCancel: 'Undo the changes
            DoCmd.RunCommand acCmdUndo
    
        Case Else: 'Default case to trap any errors.
            'Do nothing
    
    End Select
    
Exit_bSave_Click:
    Exit Sub
    
Err_bSave_Click:
    If Err = 2046 Then 'The command or action Undo is not available now
        Exit Sub
    Else
        ErrorMsg Me.Name, "bSave_Click", Err.Number, Err.Description
        Resume Exit_bSave_Click
    End If
    
End Sub

HTH
 

Users who are viewing this thread

Back
Top Bottom