Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    223

    Unanswered: How to Save a record and Close Form

    Code:
    Private Sub cmdExitForm_Click()
    
    On Error GoTo Err_cmdExitForm_Click
    If MsgBox("Do you want to Save the record?", vbYesNo + vbInformation, "Please confirm:") = vbYes Then
       If Me.Parent.Dirty = True Then Me.Parent.Dirty = False
        DoCmd.Close
    
    Exit_cmdExitForm_Click:
        Exit Sub
    
    Err_cmdExitForm_Click:
        MsgBox Err.Description
        Resume Exit_cmdExitForm_Click
        
    End Sub
    any clues to where i am going wrong?

    I have been trying to create correct code for a command button which will ask if the user if he wants to save a record before exit, if the record has not been saved.

    hehehe - i have tried so many ways but not been successful. The error message is Block If without EndIf. But i hav erecieved so many other error messages when i try to change the code
    Last edited by reddevil1; 01-03-13 at 14:37.
    What would you attempt to do if you knew you would not fail?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so the message is
    Block If without EndIf
    so examine your code and see if the compiler is lying (doubtful)
    is every if terminated by an endif

    is this a question that needs intervention from others or is it a question that you coudl probably sort out yourself if you gave it some thought AND reacted to the compilers whinge
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Nov 2009
    Posts
    223
    Private Sub cmdExitForm_Click()

    On Error GoTo Err_cmdExitForm_Click
    If MsgBox("Do you want to Save the record?", vbYesNo + vbInformation, "Please confirm:") = vbYes Then
    If Me.Parent.Dirty = True Then Me.Parent.Dirty = False
    DoCmd.Close
    End If
    Exit_cmdExitForm_Click:
    Exit Sub

    Err_cmdExitForm_Click:
    MsgBox Err.Description
    Resume Exit_cmdExitForm_Click

    End Sub
    Cheers healdem - yup, maybe a bit of laziness...i have been working 16 hours and it is late at night already.

    I eventually found where to put the End If.
    What would you attempt to do if you knew you would not fail?

  4. #4
    Join Date
    Nov 2009
    Posts
    223
    But i found that if the user says "no" to the "do you want to save" question, the change in the record is saved anyway?
    What would you attempt to do if you knew you would not fail?

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what part of your code do think doers anything that saves or cancels saving?
    the default behaviours of an Access form that uses 'bound' controls is to save chanegs on exit
    if you want to override that behaviour then you have to place the code int he appropriate event
    which is the myformname_exit function
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •