使用组合框来搜索“选项组”中的多个字段。 [英] Using a combobox for searching multiple fields in "option group"

查看:73
本文介绍了使用组合框来搜索“选项组”中的多个字段。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我还有几个搜索问题。

我有一个搜索表单,frm_Search。

我想要过滤的表格,frm_Form1

frm_Search上的未绑定组合框,Cbo_Permit

在frm_Form1,fld_Permit1,fld_Permit2中绑定到tbl_Table1的6个不同字段...


6个绑定字段位于自定义的选项组中。这样用户可以通过复选框选择相关的许可证。我知道这是一个糟糕的设计,因为表中有多个字段,但它在表单上看起来很好,每个记录可以有多个许可。


我想要的是在frm_Search,Cbo_Permit中使用未绑定的组合框,使用上面显示的字段的名称。然后,用户在组合框中选择许可并按下命令按钮以打开过滤到该特定许可的frm_Form1。


我需要知道这是否可行,因为它将是用户将进行的主要搜索之一。


使用其他搜索我已经使用了代码:

Hi,

I''m still having a couple problems with searches.
I have a search form, frm_Search.
The form I am trying to filter, frm_Form1
An unbound combobox on frm_Search, Cbo_Permit
6 different fields bound to tbl_Table1 within frm_Form1, fld_Permit1, fld_Permit2...

The 6 bound fields are within a custom made "option group" so that users can select the related permit(s) via check boxes. I understand this is a poor design because of multiple fields in the table but it looks good on the form and each record can have multiple permits.

What I would like, is to use an unbound combobox within frm_Search, Cbo_Permit, using the names of the fields I shown above. The user then selects a permit within the combobox and presses a command button to open frm_Form1 filtered to that particular permit.

I need to know if this is possible as it will be one of the main searches users will make.

With other searches I''ve used the code:

展开 | 选择 | 换行 | 行号

推荐答案

Leigh,


如果我理解正确,你希望frm_Search根据组合框的值过滤frm_Form1中的记录,其中if有人选择Permit1,然后表单将只显示使用Permit1的记录,如果用户选择Permit2,那么只有Permit2记录,依此类推......这是正确的吗?


首先,知道许可是否会很好字段是文本字段或是/否复选框。我建议将它们设为是/否字段,因为这样代码非常容易。假设是这种情况,我会删除选项组(因为我不确定它是否能够很好地覆盖多个字段,并且只用你的六个复选框(chkPermit1,chkPermit2等)替换它。


然后,当有人选中任何一个复选框时,在他们点击命令按钮(我们称之为cmdSearch)后,会触发以下代码:

Leigh,

If I understand you correctly, you want the frm_Search to filter records in frm_Form1 based on the value of the combo box in which if someone selects Permit1, then the form will only show records in which Permit1 is used, if the user selects Permit2, then only Permit2 records, and so on.... Is this correct?

First, it would be nice to know if the permit fields are text fields or Yes/No check boxes. I would recommend making them Yes/No fields, because then this code is incredibly easy. Assuming this is the case, I would remove the Option Group (because I''m not sure it works well covering multiple fields anyway, and replace it with just your six Check Boxes (chkPermit1, chkPermit2, etc.).

Then, when someone selects any of those check boxes, after they click a command button (we''ll call it cmdSearch) the following code fires:

展开 | 选择 | Wrap | >行号


再次感谢twinnyfo。


许可字段是是/否复选框与您预期的一样。一世''我已经将搜索表单中的组合框更改为一组带有命令按钮的复选框。


唯一的问题是当我单击命令按钮时,上面的代码会出现Run-时间错误3075.查询表达式中的语法错误(缺少运算符)。它突出显示了Cmd.OpenForm行,但我认为它意味着strFilter。


尝试编辑部分代码但尚未工作
Thank you again twinnyfo.

The permit fields are yes/no check boxes like you expected. I''ve changed the combobox in the search form to a set of checkboxes with a command button.

The only problem is when I click the command button with the code above it comes up with Run-Time Error 3075. Syntax error (missing operator) in query expression. It highlights the Cmd.OpenForm line but I believe it means strFilter.

Trying to edit some of the code but not working as of yet


Leigh,

再次运行你的代码......当它出错时,选择调试选项...

现在打开VBA编辑器我们可以得到那个字符串:

< ctrl>< g>打开即时窗口

类型?strFilter 然后按回车

这将显示字符串已评估的内容和你可以将它剪切并粘贴在这里...或者它可能是显而易见的问题...

-z
Leigh,
run your code again... when it errors, select the debug option...
Now with the VBA editor open we can get at that string:
<ctrl><g> to open the immediate window
type ?strFilter and press enter
this will show what the string has evaluated to and you can cut and paste it back here... or it may be obvious what the issue is with it...
-z


这篇关于使用组合框来搜索“选项组”中的多个字段。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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