Results 1 to 10 of 10
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Tags property manipulate group of fields

    I'm wondering if you can manipulate any fields on a form by using the tag property.



    Selecting all fields I want to manipulate and giving them the same tag (almost grouping them).

    Then I want to have it so that AfterUpdate on another field it changes the property of all the tagged fields to hide/show.

    Does access allow this and how would you type in the tag in the expression builder? this would save me some time rather than having to code in every field I want to manipulate I would prefer a blanket method and I am hoping tags does this.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yes, you can.

    In its simplest form, this is the code:
    Code:
    Dim ctrl As Control 
       For Each ctrl In Me.Controls
           If ctrl.Tag = "groupABC" Then
             ctrl.Visible = False
           End If
       Next
    Note: you can not hide the control if it has the focus.


    Also, see http://stackoverflow.com/questions/1...an-access-form

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I have a combo box with drops downs.

    I'm hoping the value in that drop down determines the visibility - say ShowsID = 6

    I was thinking

    Iff(ShowsID=6) etc.

    Would showsID become ctrl?

    The dim is the variable that I am making right? however how do I make the combo box affect the ctrl function?

    Then I could do something like iff(ShowsID = 6, ctrl.visible=True,ctrl.visible=false) ?

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    see above post - I updated

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't understand what you mean.

    Here is an example.

    In the header of a form, there is an unbound combo box named "cboHideShow".
    The combo box row source type property is "Value List".
    The combo box row source property is "False";"True"
    The combo box limit to list property is YES.
    The combo box label caption property is "Visible"
    The combo box default value is TRUE
    The combo box Format property is set to "True/False"


    In the details section there are one or more controls with "Selected" in the Tag property.

    The combo box "cboHideShow" after update event has this code:
    Code:
    Private Sub cboHideShow_AfterUpdate()
        Dim ctl As Control
    
        For Each ctl In Me.Controls
        If ctl.Tag = "Selected" Then
          ctl.Visible = Me.cboHideShow
          End If
        Next ctl
        Set ctl = Nothing
    End Sub
    Setting the combo box "cboHideShow" to FALSE hides the controls.
    Setting the combo box "cboHideShow" to TRUE shows the controls.

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ssanfu View Post
    I don't understand what you mean.

    Here is an example.

    In the header of a form, there is an unbound combo box named "cboHideShow".
    The combo box row source type property is "Value List".
    The combo box row source property is "False";"True"
    The combo box limit to list property is YES.
    The combo box label caption property is "Visible"
    The combo box default value is TRUE
    The combo box Format property is set to "True/False"


    In the details section there are one or more controls with "Selected" in the Tag property.

    The combo box "cboHideShow" after update event has this code:
    Code:
    Private Sub cboHideShow_AfterUpdate()
        Dim ctl As Control
    
        For Each ctl In Me.Controls
        If ctl.Tag = "Selected" Then
          ctl.Visible = Me.cboHideShow
          End If
        Next ctl
        Set ctl = Nothing
    End Sub
    Setting the combo box "cboHideShow" to FALSE hides the controls.
    Setting the combo box "cboHideShow" to TRUE shows the controls.
    The combo box is a value.

    If the value is a certain number - say 5, then it hides all fields on the form that have the same tag (this particular tag is called "CancellationArea").

    I figured it would be simple that anything with the "CancellationArea" tag would vanish with a simple iff

    I was hoping to have on StatusID on an AfterUpdate

    iff(StatusID = 5, CancellationArea = Visible, CancellationArea = False)
    But because CancellationArea isn't a field it won't hold it's own value of Yes or No to visibility.

    I guess that is why you make CancellationArea = a dim and then make that visible or not...?

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    iff(StatusID = 5, CancellationArea = Visible, CancellationArea = False)

    But because CancellationArea isn't a field it won't hold it's own value of Yes or No to visibility.
    This will never work. The Visible property requires a selection from the list. the options are Yes/No.



    I guess that is why you make CancellationArea = a dim and then make that visible or not...?
    I have no idea what you mean by this...


    If you have a combo box named "StatusID" where the bound column returns a 5 or 6,
    AND you have some controls that have "CancellationArea" in the "Tag" property OR "Selected",
    the following code will hide or show the fields:
    Code:
    Private Sub StatusID_AfterUpdate()  '<< combo box name
       Dim ctl As Control
    
       For Each ctl In Me.Controls
          Select Case Me.StatusID '<< combo box name
             Case 4
    
             Case 5     '<< combo box value
                If ctl.Tag = "CancellationArea" Then
                   ctl.Visible = False
                Else
                   ctl.Visible = True
                End If
             Case 6
                If ctl.Tag = "Selected" Then
                   ctl.Visible = False
                Else
                   ctl.Visible = True
                End If
          End Select
       Next ctl
       Set ctl = Nothing
    End Sub
    If I knew the combo box name, all the values returned and the all of the text in the Tag property of the controls on the form, I could have the code closer to what you want.

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ssanfu View Post
    This will never work. The Visible property requires a selection from the list. the options are Yes/No.




    I have no idea what you mean by this...


    If you have a combo box named "StatusID" where the bound column returns a 5 or 6,
    AND you have some controls that have "CancellationArea" in the "Tag" property OR "Selected",
    the following code will hide or show the fields:
    Code:
    Private Sub StatusID_AfterUpdate()  '<< combo box name
       Dim ctl As Control
    
       For Each ctl In Me.Controls
          Select Case Me.StatusID '<< combo box name
             Case 4
    
             Case 5     '<< combo box value
                If ctl.Tag = "CancellationArea" Then
                   ctl.Visible = False
                Else
                   ctl.Visible = True
                End If
             Case 6
                If ctl.Tag = "Selected" Then
                   ctl.Visible = False
                Else
                   ctl.Visible = True
                End If
          End Select
       Next ctl
       Set ctl = Nothing
    End Sub
    If I knew the combo box name, all the values returned and the all of the text in the Tag property of the controls on the form, I could have the code closer to what you want.
    The combobox is StatusID

    The tag (whatever form fields they are) have CancellationArea

    and the selection from StatusID is 6 (ID) which results with "CANCELLED" All the other ID's return values of course but they don't need to create an action like 6 does (for now).

    The idea is that once the status of the booking is changed to cancelled a box appears with all the relevant fields and the user can fill those fields in.

    I get your method. I got the action working fine with the slow method of course but that meant I had to add each field into the code rather than a blanket tag, making your method a lot better for use for a number of reasons.

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Guessing...
    Code:
    Private Sub StatusID_AfterUpdate()  '<< combo box name 
      
    Dim ctl As Control 
      
    For Each ctl In Me.Controls      Select Case Me.StatusID '<< combo box name 
                   If ctl.Tag = "CancellationArea" 
    Then ctl.Visible = False            
    Else  ctl.Visible = True 
               End If         
               
    If ctl.Tag = "6" 
    Then ctl.Visible = False 
    Else ctl.Visible = True 
               End If 
         End 
    Select   Next ctl   Set ctl = Nothing '<< combo box name can we really just type nothing? :confused:
    End Sub

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I've been going back to this and using it - however it saves the form in that state

    I'd like the form to return to it's original state without saving - will that work?

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

Similar Threads

  1. Remove some certain words, tags in fields
    By shinichi_nguyen in forum Access
    Replies: 1
    Last Post: 08-09-2013, 01:44 PM
  2. manipulate file before import
    By tagteam in forum Programming
    Replies: 3
    Last Post: 06-14-2013, 12:45 PM
  3. Using VBA to manipulate properties in a Report
    By adacpt in forum Programming
    Replies: 1
    Last Post: 11-26-2012, 09:22 PM
  4. Replies: 6
    Last Post: 09-27-2011, 04:39 PM
  5. Manipulate DB through VB ...
    By Zoroxeus in forum Programming
    Replies: 2
    Last Post: 12-18-2005, 01:16 PM

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