遍历TabControl中的选项卡以根据名称隐藏选项卡 [英] Iterate through tabs in TabControl to hide tabs based on names

查看:429
本文介绍了遍历TabControl中的选项卡以根据名称隐藏选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Access数据库(Office 2010),并且在窗体底部有一个选项卡控件,该控件可根据您选择的设备类型显示设备信息.我正在尝试使其动态显示和隐藏由选项卡名称确定的选项卡.

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

我的TabControl称为标签"

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.

推荐答案

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

无效的VBA语法.您可能正在考虑在VB.NET中可用的一些类似方法.在VBA中,您会做类似的事情

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

这篇关于遍历TabControl中的选项卡以根据名称隐藏选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆