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

    Tag visibility using for loop on control

    I get an expression error when using this code and I can't figure out why



    Code:
    Function tagVisibility()
    
    
    
    
    Dim ctl As Control
    
    
    If IsNull(Me.DateFrom_Box) Or IsNull(Me.DateUntil_Box) Then
    
    
    For Each ctl In Form.Controls
        If ctl.Tag = "Vanish" Then
        ctl.Visible = False
        Else
        ctl.Visible = True
        End If
        Next ctl
    Else
        For Each ctl In Form.Controls
        If ctl.Tag = "Vanish" Then
        ctl.Visible = True
        End If
        Next ctl
        Me.ListOfSchools.Requery
    End If
    
    
    End Function

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I fixed it by removing the snapping layout as it errored around empty cells.... but why? They don't have the visible property but out how do you avoid them in a loop?

  3. #3
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119
    You can test for ctl.ControlType, and then use a SELECT CASE statement for the ones that have the Visible property. The ControlType enums can be found here.

    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by thebigthing313 View Post
    You can test for ctl.ControlType, and then use a SELECT CASE statement for the ones that have the Visible property. The ControlType enums can be found here.

    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    Thanks - that worked well

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

Similar Threads

  1. Replies: 13
    Last Post: 08-20-2014, 09:17 AM
  2. Replies: 17
    Last Post: 04-07-2014, 07:48 PM
  3. Replies: 8
    Last Post: 09-19-2013, 03:07 PM
  4. a loop using vba to change control name
    By Chuck55 in forum Programming
    Replies: 4
    Last Post: 04-23-2012, 09:23 PM
  5. Out of control loop in autoexec macro
    By accessnewbie in forum Programming
    Replies: 2
    Last Post: 08-19-2010, 04:31 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