Results 1 to 5 of 5
  1. #1
    twpt is offline Novice
    Windows Vista Access 2003
    Join Date
    Jul 2012
    Posts
    2

    validate checkbox when saving a record/form

    Hi everyone,

    I studied a bit of Database design many many years ago at uni so know a little bit but am pretty rusty. I have built a new client database and have a question on a (fairly) simple task.

    I have a checkbox on a form (essentially a disclaimer). I would like to have a pop up that appears if you try to save the form without checking the box. Similar to a box that asks you to agree to terms and conditions before clicking ok on a website.

    Any help massively appreciated.

    Thanks,



    ed

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I'd use the before update event of the form:

    http://www.baldyweb.com/BeforeUpdate.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The Form_BeforeUpdate is the correct event for this, of course, and your code will work for most Controls, but it won't work for a Checkbox Control. That's because a Checkbox has an Access defined Default of Zero (0). For a Checkbox you'd need check for a Value of -1, with something like this:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Disclaimer <> -1 Then
      MsgBox "You need to Tick the Disclaimer  Box"
      Cancel = True
      Me. Disclaimer.SetFocus
    End If
    End Sub


    Linq ;0)>

  4. #4
    twpt is offline Novice
    Windows Vista Access 2003
    Join Date
    Jul 2012
    Posts
    2
    Brilliant stuff guys, thanks a lot. I put the code in the on click event on the save button in the end, as if i put it in the form it caused a problem when you closed the form. The msg box would show, but not allow you to change the status of the checkbox. Seems to work fine on the save button.

    Many Thanks, has saved me a load of time.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by twpt View Post
    Brilliant stuff guys, thanks a lot. I put the code in the on click event on the save button in the end, as if i put it in the form it caused a problem when you closed the form. The msg box would show, but not allow you to change the status of the checkbox. Seems to work fine on the save button.
    Sorry, but that makes no sense, on several counts!


    To begin with, if the code was used in the Form_BeforeUpdate event, there is no reason for you not be be able to tick the Checkbox. One of the points in having the Validation code in this event is that it will work regardless of whether the user moves to another Record, closes the Form or closes Access, itself.

    What, exactly, does your 'Save' button do? Such a button, in Access, is unnecessary, the Record being automatically saved when the Record is moved off of, and frequently ends up causing trouble. If you must have one, it should either merely move to a New Record or Close the Form.

    Secondly, you cannot use the Cancel event with the OnClick Event of a Command Button; it has no Cancel event. This means that although you'll see the message, the Record will still be saved, with the Checkbox unticked.

    Linq ;0)>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Message Box for Saving Record
    By Mahavir in forum Access
    Replies: 5
    Last Post: 12-29-2011, 12:13 PM
  2. If Statement to validate Field on a Form
    By ETCallHome in forum Forms
    Replies: 4
    Last Post: 04-05-2011, 05:22 PM
  3. Saving Record
    By mwabbe in forum Programming
    Replies: 12
    Last Post: 09-15-2010, 12:09 PM
  4. record saving twice in table
    By ds_8805 in forum Forms
    Replies: 15
    Last Post: 04-14-2010, 07:16 PM
  5. Replies: 2
    Last Post: 11-04-2009, 09:45 PM

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