在MS-Access中以编程方式隐藏列 [英] Hide a column programmatically in MS-Access

查看:152
本文介绍了在MS-Access中以编程方式隐藏列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据用户选择的可变数据来隐藏或显示一列。你如何设置一个隐藏在MS-Access 2003中的列?



例如,

用户更改事件后...

  For Each ctl In Me.FormNameHere.Form.Controls 
If(TypeName(ctl)=Textbox)Then
If InStr(GetTextList ),ctl.Name)> 0 Then
ctl.hidden = True
Else
ctl.hidden = False
End If
End If
Next ctl




  • 这种类型的挑战最好的办法是什么?

  • 是否有更明显的解决方案?
  • >控件没有隐藏属性(Access中没有对象具有隐藏属性)。他们有一个.Visible属性。

    为了将来的参考,我建议你熟悉VBE中的对象浏览器 - 打开VBE并按F2。然后,您可以将搜索范围限制为项目中使用的各个库。但是,要理解对象模型还需要一段时间。



    另外,您可以依靠Intellisense学习对象的属性/方法,所以在你使用的表单的代码中,你可以输入Me.MyTextBox。智能感应下拉菜单将显示特定控制的所有属性和方法。它不适用于泛型控制变量(如代码中),因为不同的控件类型具有不同的属性。



    当然,属性表给出了名称即使在代码中,它们并不总是使用相同的拼写法(通常它们与空格去除相同)。



    另外,你可能想要这样做取决于它是一个常规的形式还是数据表形式。在数据表中,您的控件还具有.ColumnHidden和.ColumnWidth属性(在数据表视图以外的任何视图中设置这些属性均不起作用,并且这些属性在标准属性表中均不可用,但在保存时会保留对其的更改表格)。


    I want to hide or show a column based on variable data from a users selection. How do you set a column to hidden in MS-Access 2003?

    For Example,

    After user change event...

    For Each ctl In Me.FormNameHere.Form.Controls
        If (TypeName(ctl) = "Textbox") Then
            If InStr(GetTextList(), ctl.Name) > 0 Then
                ctl.hidden = True
            Else
                ctl.hidden = False
            End If
        End If
    Next ctl
    

    • What is the best approach to this type of challenge?
    • Is there a more obvious solution?

    解决方案

    Controls do not have a "hidden" property (no objects in Access have a hidden property). They do have a .Visible property.

    For future reference, I suggest you familiarize yourself with the Object Browser in the VBE -- open the VBE and hit F2. You can then restrict your search to the individual libraries used in your project. It does take a while to get to the point where you understand the object model, though.

    Also, you can rely on Intellisense to learn the properties/methods of an object, so in the code of the form you're working with, you can type "Me.MyTextBox." and the Intellisense dropdown will show you all the properties and methods of that particular control. It doesn't work for a generic control variable (as in your code) because different control types have different properties.

    And, of course, the properties sheet gives the names of the properties, even though in code they don't always use the same orthography (usually they are the same with spaces removed).

    Also, there are differences in how you might want to do this depending on whether it's a regular form or a datasheet form. In a datasheet, your controls also have .ColumnHidden and .ColumnWidth properties (setting those in any view other than datasheet view has no effect, and neither of those properties are available in the standard property sheet, but changes to them are retained when you save the form).

    这篇关于在MS-Access中以编程方式隐藏列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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