Iterate through tabs in TabControl to hide tabs based on names

谁都会走 提交于 2020-01-15 20:21:51

问题


I am working on a Microsoft Access Database (Office 2010) and I have a tab control on the bottom of my form that displays equipment information based on the type of equipment you select. I am trying to make it dynamically display and hide tabs as determined by the name of the tabs.

To accomplish this I have used the following naming convention for my tabs.

Tab_Static_Description
Tab_Static_Comments
Tab_Static_Maintenance
Tab_Config_Computer1
Tab_Config_Computer2
Tab_Config_Printer1
Tab_Config_Scanner1
Tab_Config_Telephone1
Tab_Config_Display1

My TabControl is called "Tabs"

I have set the form to execute the function below(the function i need help with) on form load and onchange of the equipment drop down menu.

To call the function i use the following code.

DisplayTab

Here is the code to far. I have been googling this a bit and I have yet to find someone doing something similar to me and have found myself a little lost on this one. Any help would be greatly appreciated.

Function DisplayTab(EquipmentType As String)
    Dim Ctl As Control
    For Each Ctl In Me.Tabs
        If Ctl.Name.contains("Tab_Static_") Then
            Me.Tabs.Pages.Item(Ctl).Visible = True
        ElseIf Ctl.Name.contains("Tab_Config_") Then
            If Ctl.Name.contains("Tab_Congig_" & EquipmentType) Then
                Me.Tabs.Pages.Item(Ctl).Visible = True
            Else
                Me.Tabs.Pages.Item(Ctl).Visible = False
            End If
        Else
            MsgBox "There is an unusually named tab. Please contact the database adminsitrator."
        End If
    Next Ctl
End Function

The error I am getting is "Invalid qualifier" but after googling that message it doesn't exactly make sense.


回答1:


If Ctl.Name.contains("Tab_Static_") Then

is not valid VBA syntax. You are probably thinking of some similar method that might be availabe in VB.NET. In VBA you would do something like

If InStr(Ctl.Name, "Tab_Static_") > 0 Then


来源:https://stackoverflow.com/questions/22610508/iterate-through-tabs-in-tabcontrol-to-hide-tabs-based-on-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!