How to show a message box to confirm saving a new record?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel B
    New Member
    • Aug 2010
    • 33

    How to show a message box to confirm saving a new record?

    I have a save button on my form that, on click, saves the new record, but I would like to have a message box appear and ask if the user is sure they want to save (yes/ok or no/cancel). Then once the user has chosen yes/ok to save the new record, the form should close.

    Any suggestions are appreciated!

    Dan B.
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2
    Should be fairly easy. What have you tried so far?

    Comment

    • Daniel B
      New Member
      • Aug 2010
      • 33

      #3
      well I am not very experienced with VB so I'm kind of lost.

      Comment

      • yarbrough40
        Contributor
        • Jun 2009
        • 320

        #4
        ok no problem... you say that your button is saving a record in a table. Are you writing this in an Event Procedure (using code) or did you simply use the wizzard when you added the button to call a record save?

        Are you familiar with writing VBA code in event procedures?

        Comment

        • Daniel B
          New Member
          • Aug 2010
          • 33

          #5
          I did it in an event procedure, but I got help on that part too. Well I understand how some of it works, but I'm not familiar with writing VBA code.

          Comment

          • yarbrough40
            Contributor
            • Jun 2009
            • 320

            #6
            ok well what you want to use is a message box with the buttons you need. It should look something like this:
            Code:
            Private Sub MyCommandButton_Click()
            
            If MsgBox("Are You Sure You Want to save ?", vbOKCancel) = vbOK Then
            ' OK was clicked....write code here to save your record
            Else
            ' Cancel was clicked...write code here to do something else
            End If
            End Sub
            If you still need help, just show me the actual code you have now that saves your record I can help you further.

            Comment

            • Daniel B
              New Member
              • Aug 2010
              • 33

              #7
              This is what I have..

              Private Sub cmdSave_Click()
              On Error GoTo Err_cmdSave_Cli ck

              If MsgBox("Are you sure you want to save?", vbOKCanecl) = vbOK Then

              DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

              Exit_cmdSave_Cl ick:
              Exit Sub

              Err_cmdSave_Cli ck:
              MsgBox Err.Description
              Resume Exit_cmdSave_Cl ick

              End If
              End Sub

              Comment

              • yarbrough40
                Contributor
                • Jun 2009
                • 320

                #8
                Looks fine to me. is it working?

                Comment

                • Daniel B
                  New Member
                  • Aug 2010
                  • 33

                  #9
                  Yup it's working perfect. Except when I click Save, how do you get the form to close?

                  Comment

                  • Daniel B
                    New Member
                    • Aug 2010
                    • 33

                    #10
                    Actually I figured it out. Thank you so much for taking the time to help me, I really appreciate it!

                    Dan B.

                    Comment

                    Working...