Solved

How to limt new records added to an Access 2013 table?

Posted on 2014-09-06
2
148 Views
Last Modified: 2014-11-28
How can I create an Access form which will only allow the user to enter just one record into a table.  This form will be emailed to a client, and will need this feature in order to avoid duplication.  Thanks
0
Comment
Question by:eq2006
2 Comments
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
Comment Utility
Do you mean the TABLE will hold only one record, or do you mean the Table will hold multiple records, but you want your client to one enter one?

If the first, then just check the record count of the table before you allow the form to update:

Sub Form_BeforeUpdate(Cancel as Integer)
  If Me.NewRecord Then
    If DCount("SomeField", "YourTableName") >0 Then
      MsgBox "You cannot add more records"
      Cancel = True
    End If
  End If
End Sub

If the second, then the best way to prevent duplication is to add a Unique Index to the table, and include the Fields that would define a duplicate record. For example, in a Customer table, I might consider the CustomerName, CustomerZip and CustomerPhone to be unique. If so, then I'd create an Index on the table, and include all three of those fields, and set the Unique property to True.
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 250 total points
Comment Utility
Have a field of data type Long Integer with a default value of 0 (zero) and set this as the Primary Key.
Don't show the field on the form.
The client may create, update, or delete this single record but cannot add another record.

/gustav
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now