永发信息网

access中,怎样实现如图查询。文本框中输入条件,下表列出满足条件内容?我初学,希望详细步骤,谢谢

答案:1  悬赏:20  手机版
解决时间 2021-03-24 04:34
access中,怎样实现如图查询。文本框中输入条件,下表列出满足条件内容?我初学,希望详细步骤,谢谢
最佳答案
这里提供详细实现方案供参考
首先假设主窗体的四个文本框、两个命令按钮和子窗体的名称分别是:

车牌号码,维保内容,维保厂家,维保日期,Command1,Command2,子窗体1
主窗体名:维保查询
假设数据表结构为:
维保记录(ID,车牌号码,维保内容,维保厂家,维保日期)


将子窗体1的记录源属性设置为:
select * from 维保记录 where false;
目的是让子窗体于窗体打开时暂时不显示记录


'为查询命令按钮编写下列单击事件过程:
Private Sub Command1_Click()
    Dim strSql As String
    '因为有4个条件框可产生2^4=16种查询组合,
    '下面用代码一次性将这16种查询方式的SQL全部拼接起来,
    '从而实现输入什么条件就按什么条件查询相关记录
    strSql = "select * from 维保记录 where "
    '四个条件均为空时输出所有维保记录
    strSql = strSql & "(Forms!维保查询!车牌号码 is null and "
    strSql = strSql & "Forms!维保查询!维保内容 is null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is null and "
    strSql = strSql & "Forms!维保查询!维保日期 is null) or "
    '只有“维保日期”一个条件时,单独按“维保日期”精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is null and "
    strSql = strSql & "Forms!维保查询!维保内容 is null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is null and "
    strSql = strSql & "Forms!维保查询!维保日期 is not null and "
    strSql = strSql & "维保日期=Forms!维保查询!维保日期) or "
    '只有“维保厂家”一个条件时,单独按“维保厂家”模糊查找
    strSql = strSql & "(Forms!维保查询!车牌号码 is null and "
    strSql = strSql & "Forms!维保查询!维保内容 is null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is not null and "
    strSql = strSql & "Forms!维保查询!维保日期 is null and "
    strSql = strSql & "维保厂家 Like '*' & Forms!维保查询!维保厂家 & '*') or "
    '双条件,按维保厂家模糊查找、维保日期精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is null and "
    strSql = strSql & "Forms!维保查询!维保内容 is null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is not null and "
    strSql = strSql & "Forms!维保查询!维保日期 is not null and "
    strSql = strSql & "维保厂家 Like '*' & Forms!维保查询!维保厂家 & '*' and "
    strSql = strSql & "维保日期=Forms!维保查询!维保日期) or "
    '只有“维保内容”一个条件时,单独按“维保内容”模糊查找
    strSql = strSql & "(Forms!维保查询!车牌号码 is null and "
    strSql = strSql & "Forms!维保查询!维保内容 is not null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is null and "
    strSql = strSql & "Forms!维保查询!维保日期 is null and "
    strSql = strSql & "维保内容 Like '*' & Forms!维保查询!维保内容 & '*') or "
    '双条件,按维保内容模糊查找、维保日期精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is null and "
    strSql = strSql & "Forms!维保查询!维保内容 is not null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is null and "
    strSql = strSql & "Forms!维保查询!维保日期 is not null and "
    strSql = strSql & "维保内容 Like '*' & Forms!维保查询!维保内容 & '*' and "
    strSql = strSql & "维保日期=Forms!维保查询!维保日期) or "
    '双条件,按维保内容模糊查找、维保厂家模糊查找
    strSql = strSql & "(Forms!维保查询!车牌号码 is null and "
    strSql = strSql & "Forms!维保查询!维保内容 is not null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is not null and "
    strSql = strSql & "Forms!维保查询!维保日期 is null and "
    strSql = strSql & "维保内容 Like '*' & Forms!维保查询!维保内容 & '*' and "
    strSql = strSql & "维保厂家 Like '*' & Forms!维保查询!维保日期 & '*') or "
    '3条件,按维保内容模糊查找、维保厂家模糊查找、维保日期精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is null and "
    strSql = strSql & "Forms!维保查询!维保内容 is not null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is not null and "
    strSql = strSql & "Forms!维保查询!维保日期 is not null and "
    strSql = strSql & "维保内容 Like '*' & Forms!维保查询!车牌号码 & '*' and "
    strSql = strSql & "维保厂家 Like '*' & Forms!维保查询!维保厂家 & '*' and "
    strSql = strSql & "维保日期=Forms!维保查询!维保日期) or "
    '只有“车牌号码”一个条件时,单独按“车牌号码”精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is not null and "
    strSql = strSql & "Forms!维保查询!维保内容 is null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is null and "
    strSql = strSql & "Forms!维保查询!维保日期 is null and "
    strSql = strSql & "车牌号码=Forms!维保查询!车牌号码) or "
    '双条件,按车牌号码和维保日期精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is not null and "
    strSql = strSql & "Forms!维保查询!维保内容 is null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is null and "
    strSql = strSql & "Forms!维保查询!维保日期 is not null and "
    strSql = strSql & "车牌号码=Forms!维保查询!车牌号码 and "
    strSql = strSql & "维保日期=Forms!维保查询!维保日期) or "
    '双条件,按车牌号码精确筛选、维保厂家模糊查找
    strSql = strSql & "(Forms!维保查询!车牌号码 is not null and "
    strSql = strSql & "Forms!维保查询!维保内容 is null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is not null and "
    strSql = strSql & "Forms!维保查询!维保日期 is null and "
    strSql = strSql & "车牌号码=Forms!维保查询!车牌号码 and "
    strSql = strSql & "维保厂家 Like '*' & Forms!维保查询!维保厂家 & '*') or "
    '3条件,按车牌号码精确筛选、维保厂家模糊查找、维保日期精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is not null and "
    strSql = strSql & "Forms!维保查询!维保内容 is null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is not null and "
    strSql = strSql & "Forms!维保查询!维保日期 is not null and "
    strSql = strSql & "车牌号码=Forms!维保查询!车牌号码 and "
    strSql = strSql & "维保厂家 Like '*' & Forms!维保查询!维保厂家 & '*' and "
    strSql = strSql & "维保日期=Forms!维保查询!维保日期) or "
    '双条件,按车牌号码精确筛选、维保内容模糊查找
    strSql = strSql & "(Forms!维保查询!车牌号码 is not null and "
    strSql = strSql & "Forms!维保查询!维保内容 is not null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is null and "
    strSql = strSql & "Forms!维保查询!维保日期 is null and "
    strSql = strSql & "车牌号码=Forms!维保查询!车牌号码 and "
    strSql = strSql & "维保内容 Like '*' & Forms!维保查询!维保内容 & '*') or "
    '3条件,按车牌号码精确筛选、维保内容模糊查找、维保日期精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is not null and "
    strSql = strSql & "Forms!维保查询!维保内容 is not null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is null and "
    strSql = strSql & "Forms!维保查询!维保日期 is not null and "
    strSql = strSql & "车牌号码=Forms!维保查询!车牌号码 and "
    strSql = strSql & "维保内容 Like '*' & Forms!维保查询!维保内容 & '*' and "
    strSql = strSql & "维保日期=Forms!维保查询!维保日期) or "
    '3条件,按车牌号码精确筛选、维保内容模糊查找、维保厂家模糊查找
    strSql = strSql & "(Forms!维保查询!车牌号码 is not null and "
    strSql = strSql & "Forms!维保查询!维保内容 is not null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is not null and "
    strSql = strSql & "Forms!维保查询!维保日期 is null and "
    strSql = strSql & "车牌号码=Forms!维保查询!车牌号码 and "
    strSql = strSql & "维保内容 Like '*' & Forms!维保查询!维保内容 & '*' and "
    strSql = strSql & "维保厂家 Like '*' & Forms!维保查询!维保厂家 & '*') or "
    '4条件,按车牌号码精确筛选、维保内容模糊查找、维保厂家模糊查找、维保日期精确筛选
    strSql = strSql & "(Forms!维保查询!车牌号码 is not null and "
    strSql = strSql & "Forms!维保查询!维保内容 is not null and "
    strSql = strSql & "Forms!维保查询!维保厂家 is not null and "
    strSql = strSql & "Forms!维保查询!维保日期 is not null and "
    strSql = strSql & "车牌号码=Forms!维保查询!车牌号码 and "
    strSql = strSql & "维保内容 Like '*' & Forms!维保查询!维保内容 & '*' and "
    strSql = strSql & "维保厂家 Like '*' & Forms!维保查询!维保厂家 & '*' and "
    strSql = strSql & "维保日期=Forms!维保查询!维保日期);"
    Me!子窗体1.Form.RecordSource = strSql  '输出查询结果
End Sub

'为清除命令按钮编写下列单击事件过程:
Private Sub Command2_Click()
    车牌号码 = Null
    维保内容 = Null
    维保厂家 = Null
    维保日期 = Null
    Me!子窗体1.Form.RecordSource = "select * from 维保记录 where false;"
End Sub 题主请按自己窗体和数据表的实际情况自行调整上述代码中涉及的窗体、控件、数据表和字段名。由于代码很长,要细心调整,不要出错漏,否则查错会比较困难。上述代码已经测试无误,上机试一试效果吧。

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
现在给b站上传视频是选微博上传还是b站直传?
啡麦品地址有知道的么?有点事想过去
氢氧化钠和氢氧化钙都是常见的碱.下列关于它
如何寄存行李最方便,想从澳门机场进,横琴口
等截面梁是什么意思?
老麦地地址在哪,我要去那里办事
在学校开展的“为灾区儿童过六一”的活动中,
螺旋输送机去哪里买最好
请问各位谁用过卫乐舒的?这个怎么样有作用么
怎样制作沙画 有哪些步骤
拉格代尔商业(上海)有限公司,有谁知道这家
神武门东西两侧供宫中老妇居住的房屋屋顶颜色
光纤宽带光信号红灯闪,打10000说您所在地区
单选题以下关于生物变异的叙述,正确的是A.基
肉的偏旁的偏旁是什么,甩的部首是什么
推荐资讯
异乡情音乐广场我想知道这个在什么地方
梦见自己的妈妈汤衣服
戒指上ctep1950b是什么意思
单选题Withtheweather________,tentooneit
创业激励正能量的句子,想起一个创业的有正能
五年级上册数学课本补充习题答案
新买的ipad air 自动设置的时间比正常快了四
单选题在美国人心目中最伟大的总统调查中,19
4.5米乡村公路不包括路面多少钱一公里,毛胚
初中生的有益书籍到了初中以后我都没怎么看过
李寄斩蛇的道理
请问北京哪里的星探最多?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?