搜索表单中的多选列表框用户选择了所选条件查询 [英] multi select list box in a search form user selected selected criteria query

查看:110
本文介绍了搜索表单中的多选列表框用户选择了所选条件查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题让我发疯了。


您好,

我正在尝试为我的访问数据库中的记录创建搜索表单。搜索表单将包含文本框和多选列表框。用户可以输入他们的搜索条件,例如。文本框中的姓氏,注册号等。多选列表框允许用户选择他们可以选择包括在搜索中的多个县。用户应该能够根据需要选择或省略标准。


我已经搞乱了最后几天的代码,但我无法集成用户从多选列表框中选择的条件。


我已经能够修复诸如名字和姓氏搜索之类的基础知识但我无法管理多用户选择选择县的列表框。


这在我的尝试中我知道它很糟糕。

展开 | 选择 | 换行 | 行号

解决方案

  1. 您可以使用以下代码构建基于多选列表框的部分SQL Where子句:

    展开 | 选择 | Wrap | 行号


    列表框ItemData是一个两列列表框,其中第0列的县号(可能是隐藏的)和第1列中的名称。决策1是决定是否搜索是按县名或县号。哪个在tblMemberDetails中,名称或数字?

    在查询设计网格中,将查询设计为始终相同,并忘记名称和区域编号。只是县。使用在设计视图中创建查询数据库窗口。从Show Table对话框中选择tblMemberDetails,然后关闭。将*拖到第1列。将County拖到第2列。根据需要使用名称或数字,我现在将假设名称。 Criteria行的第2列输入您知道存在的县,例如Limerick。在它下面,输入另一个,说Tipperary。按查询设计工具栏上的查看按钮(最左侧的按钮)。你得到预期的结果吗?如果不是,那么你需要找出原因,但如果表中有这些县,它应该可以工作。如果没有,请选择2你知道存在。

    它有效,所以单击View按钮旁边的向下箭头,然后选择SQL。这是Access生成的SQL语句。它不会像ADezii建议的那样使用IN关键字,但你可以稍后再这样做。

    将查询窗口中的代码放入代码中,将此字符串分配给strSQLHead替换行中的循环6到17.然后包括你的strSQLHead所以你有

    展开 | 选择 | Wrap | 行号


    展开 | 选择 | Wrap | 行号


    This problem is driving me crazy.

    Hello there,
    i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user can enter their search criteria eg. surname, reg num, etc. in the text boxes. The multi select list box allows the user to select multiple counties which they have the option of including in the search. The user should be able to select or omit the criteria as they desire.


    I have messed around with the code for the last days but i am unable to intergrate the user selected criteria from a multi select list box.


    I have been able to fix to the basics like first name and surname search but i cant manage the user selection from the multi select list box of counties.

    This in my attempt it''s bad i know.

    Expand|Select|Wrap|Line Numbers

    解决方案

    1. You can build a partial SQL Where Clause based on a Multi-Select List Box with the following code:

      Expand|Select|Wrap|Line Numbers


    listbox ItemData is a two column listbox, with the county numbers in column 0 (probably hidden) and the names in column 1. Decision 1 is to decide whether search is by county name, or county number. Which is in tblMemberDetails, the name or the number?
    In the query design grid, design your query as if it were always the same, and forget the names and region numbers. Just the counties. Use the "Create query in Design View" of the Database window. Select tblMemberDetails from the Show Table dialog, and close. Drag the * to column 1. Drag the County to column 2. Use name or number as appropriate, I am going to assume name for now. Column 2, of Criteria row, enter a counties you know exists, say "Limerick" and below it, enter another, say "Tipperary". Press the View button on the Query Design Toolbar (far left button). Do you get the results expected? If no, then you need to find out why, but it should work if you have these counties in the table. If not, pick 2 you know exist.
    It works, so click the downarrow next to the View button, and select SQL. This is the SQL statement Access generates. It won''t use the IN keyword as suggested by ADezii, but you can do that later.
    Put the code from the query window into your code, assigning this string to strSQLHead replacing the loops in lines 6 to 17. Then include your strSQLHead so you have

    Expand|Select|Wrap|Line Numbers


    Expand|Select|Wrap|Line Numbers


    这篇关于搜索表单中的多选列表框用户选择了所选条件查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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