{"id":663,"date":"2013-03-31T13:43:37","date_gmt":"2013-03-31T13:43:37","guid":{"rendered":"http:\/\/regina-whipp.com\/blog\/?p=663"},"modified":"2016-07-08T22:47:19","modified_gmt":"2016-07-09T02:47:19","slug":"tag-youre-it","status":"publish","type":"post","link":"https:\/\/regina-whipp.com\/blog\/?p=663","title":{"rendered":".Tag, you&#8217;re it&#8230;"},"content":{"rendered":"<p>The .Tag Property, not to be confused with Smart Tags, \u00a0of a Control is probably the most under used and confusing Property of all.\u00a0 So what do you do with it?\u00a0 Here&#8217;s some examples&#8230;<\/p>\n<p>1. Use it to Lock bound Controls&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim ctl As Control\r\nDim frm As Form\r\n\r\nFor Each ctl In frm.Controls\r\nIf ctl.Tag = &quot;LockMe&quot; then\r\n\u00a0\u00a0 ctl.Locked = True\r\nEnd If\r\nNext ctl\r\n<\/pre>\n<p>Then any Control that has LockMe as a Tag will be locked.<\/p>\n<p>You want to put it in a Module and call it in the After_Update of the control but you should also consider a way to unlock in case corrections have to be made.<\/p>\n<p>2. Use it to validate that data has been entered in a specified field&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nPublic Function frmValidateData() As Boolean\r\nOn Error GoTo ErrHandler\r\n\r\n\u00a0\u00a0\u00a0 Dim ctl As Control\r\n\u00a0\u00a0\u00a0 Dim blnValid As Boolean\r\n\u00a0\u00a0\u00a0 Dim frm As Form\r\n\r\n\u00a0\u00a0\u00a0 Set frm = Screen.ActiveForm\r\n\u00a0\r\n\u00a0 blnValid = True\r\n\u00a0\r\n\u00a0 For Each ctl In frm.Controls 'Only use if no subform involved\r\n\u00a0\u00a0\u00a0 If ctl.Tag &lt;&gt; &quot;&quot; Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 If ctl.Enabled Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If InStr(1, ctl.Tag, &quot;require&quot;) Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If Nz(ctl, &quot;&quot;) = &quot;&quot; Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 blnValid = False\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MsgBox (ctl.Name &amp; &quot; cannot be empty.&quot;)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ctl.SetFocus\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GoTo Complete\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0 End If\r\n\u00a0 Next ctl\r\n\u00a0\r\nComplete:\r\n\u00a0 Set ctl = Nothing\r\n\u00a0 frmValidateData = blnValid\r\n\u00a0 Exit Function\r\n\r\nErrHandler:\r\n\u00a0 blnValid = False\r\n\u00a0 MsgBox (&quot;Error validating: &quot; &amp; Err.Description)\r\n\u00a0 Resume Complete\r\nEnd Function\r\n<\/pre>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-670 size-full\" src=\"http:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/Tag.png\" alt=\"Tag\" width=\"730\" height=\"302\" srcset=\"https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/Tag.png 730w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/Tag-300x124.png 300w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/Tag-150x62.png 150w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/Tag-400x165.png 400w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>3. Use it to Lock a Field after it&#8217;s been edited&#8230;<\/p>\n<p>Posted by\u00a0Ken Sheridan in the <a href=\"http:\/\/answers.microsoft.com\/en-us\/office\/forum\/access?tab=all&amp;tm=1363187189390\" target=\"_blank\">Microsoft Answers Forum<\/a> in this thread <a href=\"http:\/\/answers.microsoft.com\/en-us\/office\/forum\/office_2010-access\/lock-a-field-after-edit\/aef6026b-81c4-4da6-b7fe-b67e3849d5d2\" target=\"_blank\">Lock Field after Edit?<\/a><br \/>\nA variation on Gina&#8217;s solution would be to put the following in the form&#8217;s Current event procedure:<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim ctl As Control\r\n\r\nFor Each ctl In Me.Controls\r\n     If ctl.Tag = &quot;LockMe&quot; then\r\n        ctl.Locked = Not Me.NewRecord\r\n     End If\r\nNext ctl\r\n<\/pre>\n<p>When you navigate to an empty new record the tagged controls will be unlocked so data can be entered, but when you navigate to a previously entered record they&#8217;ll be locked.\u00a0 If you did want to add an <i>&#8216;Enable Edits&#8217;<\/i> button to the form so that existing records can be edited the code for the button&#8217;s Click event procedure would be:<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim ctl As Control\r\n\r\nFor Each ctl In Me.Controls\r\n     If ctl.Tag = &quot;LockMe&quot; then\r\n        ctl.Locked = False\r\n     End If\r\nNext ctl\r\n<\/pre>\n<p>4. Use it to Call a Module&#8230;<\/p>\n<p>Posted by <a href=\"http:\/\/www.accessmvp.com\/djsteele\/AccessIndex.html\" target=\"_blank\">Doug Steele<\/a> in the <a href=\"http:\/\/answers.microsoft.com\/en-us\/office\/forum\/access?tab=all&amp;tm=1363187189390\" target=\"_blank\">Microsoft Answers Forum<\/a> in this thread <a href=\"http:\/\/answers.microsoft.com\/en-us\/office\/forum\/office_2007-access\/use-tag-property-of-control-to-call-module\/d329ed57-9b46-4228-bc15-b7e861b61655\" target=\"_blank\">Use Tag Property of Control to Call Module<\/a><\/p>\n<p>One approach would be do create a function in the form&#8217;s module along the lines of:<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nFunction HandleClickEvent()\r\n\r\n     Select Case ActiveControl.Tag\r\n        Case &quot;DoThis&quot;\r\n        Call MyModule\r\n        Call &quot;Do That&quot;\r\n        Call\u00a0MyOtherModule\r\n     Case Else\r\n        ' Do nothing\r\n     End Select\r\n\r\nEnd Function\r\n<\/pre>\n<p>Now, you can set the On Click property of each of the 4 buttons to <strong>=HandleClickEvent()<\/strong>, rather than <strong>[Event Procedure]<\/strong>. Note that for this to work, it must be a function (not a sub), and you must include the equal sign and parentheses.<\/p>\n<p>5.\u00a0 Use it to Lock (and color) specific fields on a Continuous Form.\u00a0 In this case I only wanted to Lock the ones that had data in them.\u00a0 So first, under Conditional Formatting&#8230;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-736 size-full\" src=\"http:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/ConditionalFormatting.png\" alt=\"ConditionalFormatting\" width=\"612\" height=\"303\" srcset=\"https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/ConditionalFormatting.png 612w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/ConditionalFormatting-300x148.png 300w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/ConditionalFormatting-150x74.png 150w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/03\/ConditionalFormatting-400x198.png 400w\" sizes=\"auto, (max-width: 612px) 100vw, 612px\" \/><\/p>\n<p>I prefer to use Cream to indicate the field is Locked but you can select any color\u00a0OR any other formatting style you like.\u00a0 Then add *<strong>LockMe<\/strong>* (no asterisks) to the the Tag Property in the Controls Property\u00a0window.\u00a0 And finally,\u00a0add the below to the On_Current event of my Continuous Form&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nFor Each ctl In Me.Controls\r\n     If ctl.Tag = &quot;LockMe&quot; And ctl.Value &lt;&gt; &quot;&quot; Then\r\n        ctl.Locked = True\r\n     End If\r\nNext ctl\r\n<\/pre>\n<p>All Done!\u00a0 Now, only the Controls that have data (and any other formatting you have applied) will be Locked which will also apply once data is entered into them.\u00a0\u00a0Immediately apply Undo and your User can *<strong>Unlock<\/strong>* the record&#8230;\u00a0 This is a biggie, so you might want to make a way for your User to either Undo or Edit the record should they decide at a later date to do so!<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_663\" class=\"pvc_stats all  \" data-element-id=\"663\" 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>The .Tag Property, not to be confused with Smart Tags, of a Control is probably the most under used and confusing Property of all. So what do you do with it? Here&#8217;s some examples&#8230;<\/p>\n<p>1. Use it to Lock bound Controls&#8230;<\/p>\n<p> Dim ctl As Control Dim frm As Form For Each ctl In frm.Controls If [&#8230;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_663\" class=\"pvc_stats all  \" data-element-id=\"663\" 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":[31,36,33,21],"class_list":["post-663","post","type-post","status-publish","format-standard","hentry","category-access-tips","category-database-design","tag-forms","tag-lock-fields","tag-modules","tag-vba","odd"],"_links":{"self":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/663","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=663"}],"version-history":[{"count":19,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/663\/revisions"}],"predecessor-version":[{"id":1276,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/663\/revisions\/1276"}],"wp:attachment":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}