Results 1 to 6 of 6
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    using ctl

    All; using 2010. I have a search form with a clear button. I forgot how to use the ctl vba code to reset my controls to null. Heres the code I found:



    Code:
    Sub ClearFormText(frm As Form)
    Dim ctl As Control
    For Each ctl In frm.Controls
    If ctl.ControlType = acTextBox Then
    ctl.Value = ""
    End If
    Next ctl
    End Sub
    I have 4 unbound text boxes to search my subform. I remember I needed to put something in either smart tags or tag on the property of the txtboxes and reference in the code but I can't remember. can anyone help please. Thanks

  2. #2
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Using the tag is one possibility to identify the controls to clear. You can access the tag by using ctl.Tag:

    Code:
    Sub ClearFormText(frm As Form)
       Dim ctl As Control
       Dim txtBx As TextBox
       For Each ctl In frm.Controls 
          If ctl.ControlType = acTextBox Then
             Set txtBx = ctl
             If txtBx.Tag = "YourFancyResetTextTag" Then
                txtBx.Value = Null
             End If
          End If
       Next ctl
    End Sub
    For this to work, you need to set the tag of the textboxes to reset to "YourFancyResetTextTag".
    Last edited by hapm; 06-24-2014 at 06:57 AM. Reason: Blame on me, forgot that Control doesn't provide the Tag property

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If you instantiate an object as a Control, you can access the Tag property. It just does not appear in intellisense.

  4. #4
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Thanks! Just what I wanted

  5. #5
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Well, I used to use Option Explicit, and the compiler doesn't like it when in explicit mode afaik. So I corrected it from mind without testing.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by hapm View Post
    Well, I used to use Option Explicit, and the compiler doesn't like it when in explicit mode afaik. So I corrected it from mind without testing.
    Good to know. Yah, been years for me since I used Option Explicit too.

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

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