{"id":538,"date":"2013-02-15T02:00:49","date_gmt":"2013-02-15T02:00:49","guid":{"rendered":"http:\/\/regina-whipp.com\/blog\/?p=538"},"modified":"2016-07-08T22:45:36","modified_gmt":"2016-07-09T02:45:36","slug":"custom-navigation-buttons","status":"publish","type":"post","link":"https:\/\/regina-whipp.com\/blog\/?p=538","title":{"rendered":"Custom Navigation Buttons&#8230;"},"content":{"rendered":"<p>While Access provides Navigation Buttons, they must always be at the bottom of the Form.\u00a0 This does not work for my Form designs (Figure 1).\u00a0 Using the code below you can put your Navigation buttons where you want them AND avoid the *No Current Record* message that happens when the underlying recordset contains no records.\u00a0 You can also apply some *conditional formatting* making them enable\/disabled based on certain criteria.<\/p>\n<p>In Figure 1, I have a Main Form with a Tab Control with several Subforms.\u00a0 While you can go back and forth and edit records new records are not added here.\u00a0 Using code in the On_Current event of the Subform I disable the Add New button.\u00a0 (To get the custom Record Count *<em>Treatment 1 of 1<\/em>* <a href=\"http:\/\/regina-whipp.com\/blog\/?p=569\" target=\"_blank\">click here<\/a>.)<\/p>\n<div id=\"attachment_633\" style=\"width: 881px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-633\" class=\"wp-image-633 size-full\" src=\"http:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/02\/Treatments.png\" alt=\"Treatments\" width=\"871\" height=\"214\" srcset=\"https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/02\/Treatments.png 871w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/02\/Treatments-300x73.png 300w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/02\/Treatments-150x36.png 150w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/02\/Treatments-400x98.png 400w\" sizes=\"auto, (max-width: 871px) 100vw, 871px\" \/><p id=\"caption-attachment-633\" class=\"wp-caption-text\">Figure 1<\/p><\/div>\n<p>However, if you open the Subform by itself, which can do from another selection on the Main Menu,\u00a0you can Add New so the Add New button becomes enabled (Figure 2)&#8230;.<\/p>\n<div id=\"attachment_580\" style=\"width: 255px\" class=\"wp-caption alignleft\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-580\" class=\"wp-image-580 size-full\" src=\"http:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/02\/NavigationButtons1.png\" alt=\"NavigationButtons1\" width=\"245\" height=\"29\" srcset=\"https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/02\/NavigationButtons1.png 245w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/02\/NavigationButtons1-150x17.png 150w\" sizes=\"auto, (max-width: 245px) 100vw, 245px\" \/><p id=\"caption-attachment-580\" class=\"wp-caption-text\">Figure 2<\/p><\/div>\n<h4><span style=\"color: #000000;\">Now for the code&#8230;<\/span><\/h4>\n<p>What are the <strong>IsLoaded<\/strong> lines?\u00a0 They are\u00a0<strong>not<\/strong> required for the Navigation Buttons to work.\u00a0\u00a0If you are just looking for Navigation Buttons then you can safely delete those lines.\u00a0 What it does do is control the scrolling of records when the Subform is opened <strong>with<\/strong> the Main Form but allow the scrolling of all records if opened as a separate Subform (Main Form).\u00a0 So, if you want to use your Form as a Main Form AND a Subform then you will need\u00a0those lines\u00a0but, of course, modify to match your field names.<\/p>\n<p>Private Sub <strong>cmdFirst<\/strong>_Click()<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOn Error GoTo SmartFormError\r\n\r\n     DoCmd.RunCommand acCmdRecordsGoToFirst\r\n\r\n     If IsLoaded(&quot;frmTreatments&quot;) Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Forms!&#x5B;frmTreatments]!&#x5B;txtTreatmentDetailID] = Me.txtTreatmentDetailID\r\n\u00a0\u00a0\u00a0\u00a0 End If\r\n\r\nExit_SmartFormError:\r\nExit Sub\r\n\r\nSmartFormError:\r\n    If Err = 2046 Or Err = 2501 Then\r\n       Resume Next\r\n    Else\r\n       MsgBox Err.Description\r\n       Resume Exit_SmartFormError\r\n    End If\r\n<\/pre>\n<p>End Sub<\/p>\n<p>Private Sub <strong>cmdPrevious<\/strong>_Click()<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOn Error GoTo SmartFormError\r\n\r\n     DoCmd.RunCommand acCmdRecordsGoToPrevious\r\n     \r\n     If IsLoaded(&quot;frmTreatments&quot;) Then\r\n            Forms!&#x5B;frmTreatments]!&#x5B;txtTreatmentDetailID] = Me.txtTreatmentDetailID\r\n     End If\r\n\r\nExit_SmartFormError:\r\nExit Sub\r\n\r\nSmartFormError:\r\n    If Err = 2046 Or Err = 2501 Then\r\n       Resume Next\r\n    Else\r\n       MsgBox Err.Description\r\n       Resume Exit_SmartFormError\r\n    End If\r\n<\/pre>\n<p>End Sub<\/p>\n<p>Private Sub <strong>cmdNext<\/strong>_Click()<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOn Error GoTo SmartFormError\r\n\r\n   If Me.CurrentRecord &amp;lt; Me.Recordset.RecordCount Then\r\n     DoCmd.RunCommand acCmdRecordsGoToNext\r\n\r\n     If IsLoaded(&quot;frmTreatments&quot;) Then\r\n            Forms!&#x5B;frmTreatments]!&#x5B;txtTreatmentDetailID] = Me.txtTreatmentDetailID\r\n     End If\r\n\r\n   End If\r\n\r\nExit_SmartFormError:\r\nExit Sub\r\n\r\nSmartFormError:\r\n    If Err = 2046 Or Err = 2501 Then\r\n       Resume Next\r\n    Else\r\n       MsgBox Err.Description\r\n       Resume Exit_SmartFormError\r\n    End If\r\n<\/pre>\n<p>End Sub<\/p>\n<p>Private Sub <strong>cmdLast<\/strong>_Click()<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOn Error GoTo SmartFormError\r\n\r\nIf Me.CurrentRecord &lt; Me.Recordset.RecordCount Then\r\n     DoCmd.RunCommand acCmdRecordsGoToLast\r\n\r\n     If IsLoaded(&quot;frmTreatments&quot;) Then\r\n            Forms!&#x5B;frmTreatments]!&#x5B;txtTreatmentDetailID] = Me.txtTreatmentDetailID\r\n     End If\r\n\r\nEnd If\r\n\r\nExit_SmartFormError:\r\nExit Sub\r\n\r\nSmartFormError:\r\n    If Err = 2046 Or Err = 2501 Then\r\n       Resume Next\r\n    Else\r\n       MsgBox Err.Description\r\n       Resume Exit_SmartFormError\r\n    End If\r\n<\/pre>\n<p>End Sub<\/p>\n<p>Private Sub <strong>cmdAddNew<\/strong>_Click()<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOn Error GoTo SmartFormError\r\n\r\n     DoCmd.RunCommand acCmdRecordsGoToNew\r\n\r\nExit_SmartFormError:\r\n   Exit Sub\r\n\r\nSmartFormError:\r\n   If Err = 2046 Or Err = 2501 Then\r\n     Resume Next\r\n   Else\r\n     MsgBox Err.Description\r\n     Resume Exit_SmartFormError\r\nEnd If\r\n<\/pre>\n<p>End Sub<\/p>\n<p>In the code below be sure to change the field names under .AddNew to match the fields on your Form&#8230;<\/p>\n<p>Private Sub <strong>cmdDuplicate<\/strong>_Click()<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOn Error GoTo Err_Handler\r\n'Modified from http:\/\/www.allenbrowne.com\/ser-57.html\r\n\r\n     Dim strSQL As String\r\n     Dim db As DAO.Database\r\n\r\nSet db = DBEngine(0)(0)\r\n\r\n     If Me.Dirty Then\r\n        Me.Dirty = False\r\n     End If\r\n\r\n     If Me.NewRecord Then\r\n        MsgBox &quot;You must be on a record to proceed.&quot;, vbInformation, &quot;Treatment&quot;\r\n     Else\r\n\r\n     'Duplicate the main record\r\n     With Me.RecordsetClone\r\n        .AddNew\r\n        !tdTreatmentID = Me.txtTreatmentID\r\n        !tdTreatmentTypeID = Me.txtTreatmentTypeID\r\n        !tdPageID = 1\r\n        !tdPositionFlag = True\r\n        .Update\r\n        .Bookmark = .LastModified\r\n\r\n'Display the duplicate.\r\nMe.Bookmark = .LastModified\r\nEnd With\r\nEnd If\r\n\r\n   Set db = Nothing\r\nExit_Handler:\r\n   Exit Sub\r\n\r\nErr_Handler:\r\n   MsgBox &quot;Error &quot; &amp; Err.Number &amp; &quot; - &quot; &amp; Err.Description, , &quot;cmdDuplicate_Click&quot;\r\n   Resume Exit_Handler\r\n<\/pre>\n<p>End Sub<\/p>\n<p>Private Sub <strong>cmdDelete<\/strong>_Click()<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOn Error GoTo Err_cmdDelete_Click\r\n\r\n     If MsgBox(&quot;You are about to Delete this record, are you sure?&quot;, vbYesNo, &quot;Delete&quot;) = vbYes Then\r\n        DoCmd.SetWarnings False\r\n        DoCmd.RunCommand acCmdDeleteRecord\r\n        DoCmd.SetWarnings True\r\n     Else\r\n        DoCmd.CancelEvent\r\n     End If\r\n\r\nExit_cmdDelete_Click:\r\nExit Sub\r\n\r\nErr_cmdDelete_Click:\r\nMsgBox Err.Description\r\nResume Exit_cmdDelete_Click\r\n<\/pre>\n<p>End Sub<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_538\" class=\"pvc_stats all  \" data-element-id=\"538\" 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:\/\/regina-whipp.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>While Access provides Navigation Buttons, they must always be at the bottom of the Form. This does not work for my Form designs (Figure 1). Using the code below you can put your Navigation buttons where you want them AND avoid the *No Current Record* message that happens when the underlying recordset contains no records. [&#8230;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_538\" class=\"pvc_stats all  \" data-element-id=\"538\" 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:\/\/regina-whipp.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":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,63],"tags":[64,18,31,53,21],"class_list":["post-538","post","type-post","status-publish","format-standard","hentry","category-access-tips","category-database-design","tag-access-tips","tag-database-design","tag-forms","tag-navigation-buttons","tag-vba","odd"],"_links":{"self":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=538"}],"version-history":[{"count":22,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":1274,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions\/1274"}],"wp:attachment":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}