Results 1 to 7 of 7
  1. #1
    cebrower is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110

    Required fields on a form

    I have a form with a number of fields that are defined as Required in the table definition. The form has a button that closes the form (DoCmd.close acForm, "Formname") but when I click that button the form simply closes without saving the record even though I've entered data in some fields and without warning that there are required fields. If I close the form by throwing it into design view I get the warning and the option to return to the form or to close without saving. How can I get the warning when using the Close button? I've tried setting warning = true, but no joy.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Have you bound the form and its controls (forms don't have fields) to the table/query?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You could use
    Code:
    If Me.Dirty Then Me.Dirty = False
    in the close event of the form?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Also, check the Similar Threads at the bottom of the page.

  5. #5
    cebrower is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110
    Thanks for all the replies. I've learned that the default value for required fields must be left blank in the table definition and in the control properties when the field is added to the form. In addition (and this one had me stumped for a while) if there are fields marked required in the table definition but not placed on the form and the data source for the form is the table itself Access will report that there are required fields left blank when you try to close the form.

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    if there are fields marked required in the table definition but not placed on the form and the data source for the form is the table itself Access will report that there are required fields left blank when you try to close the form.
    Which makes perfect sense. Just because you don't add a required field to a form (which would be odd) doesn't mean that the fields validation is ignored. BTW, it would not matter if the recordsource was a query (instead of a table). Same result because the record is regarded as a whole.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    cebrower is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110
    There were fields in the table that were not added to the form because I had created some fields that I later discovered were not needed. They are gone now.

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

Similar Threads

  1. Highlighting required fields on a form
    By decco21 in forum Forms
    Replies: 6
    Last Post: 02-18-2015, 08:26 PM
  2. Message for Required Fields in Form
    By tngirl in forum Forms
    Replies: 3
    Last Post: 03-19-2014, 08:25 AM
  3. Replies: 11
    Last Post: 01-28-2013, 12:11 PM
  4. Creating Required Fields on a form
    By topp in forum Access
    Replies: 4
    Last Post: 06-27-2012, 03:20 PM
  5. Required Fields in a Form
    By Alaska1 in forum Access
    Replies: 3
    Last Post: 12-23-2010, 01:41 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