{"id":173,"date":"2014-05-20T20:33:47","date_gmt":"2014-05-21T00:33:47","guid":{"rendered":"http:\/\/access-diva.com\/blog\/?p=173"},"modified":"2015-12-30T23:03:14","modified_gmt":"2015-12-31T04:03:14","slug":"limit-number-of-record-entries","status":"publish","type":"post","link":"https:\/\/access-diva.com\/blog\/?p=173","title":{"rendered":"Limit Number of Record Entries"},"content":{"rendered":"<p>Every once in a while you may want to restrict how many records can be entered. Maybe because of space limitations on a Report or perhaps you want to limit CD rentals to 4 per Customer or book a specific amount people per room. Whatever the reason here\u2019s some code to make it happen&#8230;\u00a0<\/p>\n<p>What I used to use (and it worked)&#8230;<\/p>\n<p>Private Sub Form_<strong>BeforeInsert<\/strong>(Cancel As Integer)<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\u00a0\u00a0 If DCount(&quot;ICS&quot;, &quot;qryIncidentCrimes&quot;) = 4 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MsgBox &quot;Only 3 Charges allowed per report, if you have additional charges you must start a new report!&quot;, vbExclamation\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Me!cboICS.Undo\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DoCmd.RunCommand acCmdUndo\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DoCmd.GoToRecord , , acPrevious\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Forms!&#x5B;frmIncidentInformation]!&#x5B;txtTimeOfOccurrence].SetFocus 'Here I set focus back to the Main Form\r\n\u00a0\u00a0 End If\u00a0\r\n<\/pre>\n<p>End Sub<\/p>\n<p>But then I found a more efficient way&#8230;\u00a0<\/p>\n<p><span style=\"color: #008000;\"><strong>In a Subform<\/strong><br \/>\n<\/span>Private Sub Form_<strong>BeforeInsert<\/strong>(Cancel As Integer)\u00a0<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\u00a0\u00a0 If Me.NewRecord = True And Me.RecordsetClone.RecordCount = 4 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MsgBox &quot;Only 4 sizes allowed per sheet!&quot;, vbExclamation + vbOKOnly, &quot;FF&amp;E Size&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DoCmd.GoToRecord , , acPrevious\r\n\u00a0\u00a0 End If\r\n<\/pre>\n<p>End Sub\u00a0<\/p>\n<p><span style=\"color: #008000;\"><strong>In a Main Form<\/strong><\/span>\u00a0<br \/>\nPrivate Sub <strong>Form_Current<\/strong>()\u00a0<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\u00a0\u00a0 If Me.NewRecord = True And Me.RecordsetClone.RecordCount = 4 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MsgBox &quot;Only 4 sizes allowed per sheet!&quot;, vbExclamation + vbOKOnly, &quot;FF&amp;E Size&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DoCmd.GoToRecord , , acPrevious\r\n\u00a0\u00a0 End If\u00a0\r\n<\/pre>\n<p>End Sub<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_173\" class=\"pvc_stats all  \" data-element-id=\"173\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/access-diva.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Every once in a while you may want to restrict how many records can be entered. Maybe because of space limitations on a Report or perhaps you want to limit CD rentals to 4 per Customer or book a specific amount people per room. Whatever the reason here\u2019s some code to make it happen&#8230; <\/p>\n<p> [&#8230;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_173\" class=\"pvc_stats all  \" data-element-id=\"173\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/access-diva.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71],"tags":[20,65],"class_list":["post-173","post","type-post","status-publish","format-standard","hentry","category-forms","tag-forms","tag-limit-records","odd"],"_links":{"self":[{"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173"}],"version-history":[{"count":5,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions"}],"predecessor-version":[{"id":309,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions\/309"}],"wp:attachment":[{"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}