如何以显示/隐藏查询列的形式制作VBA代码? (MS-访问) [英] How to make a vba code in a form that show/hides query columns? ( MS- Access)

查看:248
本文介绍了如何以显示/隐藏查询列的形式制作VBA代码? (MS-访问)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用Access非常陌生,并且在编写VBA代码时遇到麻烦,该代码可能会执行以下操作:

I am extremely new to working with Access and am having trouble with writing VBA code that will would do something like this:

Private Sub YesNoShowHide ()

        If DateTested_checkbox = 'yes'
            Then show 'DateTested' column in 'search query' query
        Else DateTested_checkbox = 'no'
            Then hide 'DateTested' column in 'search query' query 
End Sub

我有一个数据库,该数据库具有一种形式,该形式将通过在文本框中键入关键字并单击搜索来执行自定义搜索",但是关键字会进入查询.我有很多字段,并且想选择一个选项,根据表格中的复选框显示或隐藏查询中的列.

I have a database that has a form that will perform a "custom search" by typing keywords into the text boxes and hitting search it will but the keywords into the query. I have many fields and would like to make a option that would show or hide the columns in the query based off the check boxes in the form.

任何帮助或建议,我们将不胜感激

Any help at all or suggestions would be appreciated

表格和图片查询

推荐答案

您可以通过使用QueryDefs.Fields.Properties集合访问查询列来显示和隐藏查询列.

You can show and hide query columns by accessing them using the QueryDefs.Fields.Properties collection.

您可以通过以下方式使用它:

You can use it in the following way:

CurrentDb.QueryDefs("search query").Fields("DateTested").Properties("ColumnHidden") = True

请注意,这将不会更改打开的查询,直到刷新后,它才会永久更改查询.如果要防止永久修改查询,可以执行以下操作:

Note that this will not change an opened query until it's refreshed, and will permanently alter the query. You can do the following if you want to prevent modifying the query permanently:

CurrentDb.QueryDefs("search query").Fields("DateTested").Properties("ColumnHidden") = True
DoCmd.OpenQuery "search query"
CurrentDb.QueryDefs("search query").Fields("DateTested").Properties("ColumnHidden") = False

这篇关于如何以显示/隐藏查询列的形式制作VBA代码? (MS-访问)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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