Results 1 to 5 of 5
  1. #1
    afr_070 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    3

    Prevent user from adding new records in database table

    Hello, I am a beginner in MS Access.

    I create a database with a table of 20 fields, a form with those 20 fields of the table and two buttons "ADD" and "SAVE". I can do the following.

    When the form load then the form fields disable to enter any data in any fields. After that I click the "ADD" button to enable all the fields and set focus on "ID" field. Then I can input data in all fields and click "SAVE" button to save the records in database table.

    And now my purpose is to check all the fields must be filled otherwise prevent user to insert data in the database table by showing error message and also clear all user form fields.

    I want help for doing this.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    set the form property: AllowEdits=false
    when the user clicks ADD or SAVE button, change it:

    Code:
    sub btnAdd_Click()
     me.AllowEdits= true
      DoCmd.GoToRecord , , acNewRec
      txtID.setfocus
    end sub

    Code:
    sub btnSave_Click()
     me.AllowEdits = false
    end sub

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    To ensure all controls on the form have been properly valued, see the BeforeUpdate event. You can determine whether record should be saved or not.

  4. #4
    afr_070 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    3
    Thanks ranman256 for your reply.

  5. #5
    afr_070 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    3
    Thanks for your reply.

    Quote Originally Posted by orange View Post
    To ensure all controls on the form have been properly valued, see the BeforeUpdate event. You can determine whether record should be saved or not.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-09-2016, 08:58 AM
  2. Replies: 6
    Last Post: 04-23-2016, 04:10 PM
  3. Prevent user adding duplicate data in form
    By littlejnz in forum Forms
    Replies: 1
    Last Post: 06-30-2014, 08:28 AM
  4. Replies: 2
    Last Post: 12-07-2011, 02:51 AM
  5. Replies: 2
    Last Post: 07-01-2010, 07:09 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