Share via

Make a button click mandatory before form update

Anonymous
2011-07-28T07:50:28+00:00

Hi

I have a form which user uses to enter a new record.

So in the form before update event i want 1 button click to be mandatory.

I have 2 buttons

  1. Save
  2. Cancel

So in the form before update event i want my user to click either one of the button before the record gets saved.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2011-07-28T10:12:35+00:00

    That's a contradictory requirement, sorry.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-07-28T09:52:00+00:00

    In my form one feild is there from diffrent table. So when my cursor reach to that feild it gives the message "Please click either Save or Cancel" which should not happen. Message should be shown only after filling all the feild.

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2011-07-28T09:37:20+00:00

    Let's say the buttons are named cmdSave and cmdCancel. You could use the following code in the form module:

    Private blnOK As Boolean

    Private Sub cmdCancel_Click()

        If Me.Dirty Then

            Me.Undo

        End If

    End Sub

    Private Sub cmdSave_Click()

        blnOK = True

        If Me.Dirty Then

            Me.Dirty = False

        End If

    End Sub

    Private Sub Form_BeforeUpdate(Cancel As Integer)

        If blnOK = False Then

            MsgBox "Please click either Save or Cancel", vbExclamation

            Cancel = True

        End If

    End Sub

    Private Sub Form_Dirty(Cancel As Integer)

        blnOK = False

    End Sub

    Was this answer helpful?

    0 comments No comments