设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12下一页
返回列表 发新帖
查看: 3828|回复: 11
打印 上一主题 下一主题

[查询] 求助窗体联动的多条件选择查询?

[复制链接]
跳转到指定楼层
1#
发表于 2008-12-29 00:18:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我做了个查询,在查询窗体中想实现实现1个或者多个条件选择查询,我些了查询的语句,可加入后没办法实现,所以我就把语句放在TXT文件里了,请求各位老师帮忙!!!!
[

[ 本帖最后由 htlsb 于 2009-1-1 00:26 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2008-12-29 00:20:00 | 只看该作者
如果能在TXT里加点简易的实现的解释方便我理解更好!
3#
发表于 2008-12-29 04:01:21 | 只看该作者
4#
 楼主| 发表于 2008-12-29 12:59:39 | 只看该作者
我就是学习刘大的查询1做的 ,不过不知道什么原因,查询语句写进查询条件就出问题查询的子窗体也不引用了
5#
发表于 2008-12-29 13:32:19 | 只看该作者
看了一下,有一点想法,不知道对不对,您可以先试一试。
您写的代码里,引用了窗体的Requery属性,不知道窗体对象有没有Requery的属性。如果有可能,还是应该先把子窗体的查询requery一下,之后再使用子窗体,这样比较稳妥。
6#
 楼主| 发表于 2008-12-29 14:00:00 | 只看该作者
这是我中午做的,可是不知道什么原因,老是引用错误,那个计数和合计是后加的,能正常使用,麻烦指点下,看看什么问题

Option Compare Database
Option Explicit

Private Sub cmd查询_Click()
On Error GoTo Err_cmd查询_Click

    Dim strWhere As String
   
    strWhere = ""
   
    If Not IsNull(Me.城区) Then
        strWhere = strWhere & "([城区] like '*" & Me.城区 & "*') AND "
    End If
   
    If Not IsNull(Me.路段) Then
        strWhere = strWhere & "([路段] like '" & Me.路段 & "') AND "
    End If

    If Not IsNull(Me.广告类型) Then
        strWhere = strWhere & "([广告类型] like '*" & Me.广告类型 & "*') AND "
    End If

    If Not IsNull(Me.广告内容) Then
        strWhere = strWhere & "([广告内容] like '" & Me.广告内容 & "') AND "
    End If
   
    If Not IsNull(Me.广告发布方) Then
        strWhere = strWhere & "([广告发布方] like '" & Me.广告发布方 & "') AND "
    End If

    If Not IsNull(Me.面积开始) Then
        strWhere = strWhere & "([面积] >= " & Me.面积开始 & ") AND "
    End If
    If Not IsNull(Me.面积截止) Then
        strWhere = strWhere & "([面积] <= " & Me.面积截止 & ") AND "
    End If
   
   
    If Not IsNull(Me.发布时间开始) Then
        strWhere = strWhere & "([发布时间] >= #" & Format(Me.发布时间开始, "yyyy-mm-dd") & "#) AND "
    End If
    If Not IsNull(Me.进书日期截止) Then
        strWhere = strWhere & "([发布时间] <= #" & Format(Me.发布时间截止, "yyyy-mm-dd") & "#) AND "
    End If
   
    If Len(strWhere) > 0 Then
        strWhere = Left(strWhere, Len(strWhere) - 5)
    End If
   
    Debug.Print strWhere
   
    Me.全城区广告查询窗体.Form.Filter = strWhere
    Me.全城区广告查询窗体.Form.FilterOn = True
   
    Call CheckSubformCount


Exit_cmd查询_Click:
    Exit Sub

Err_cmd查询_Click:
    MsgBox Err.Description
    Resume Exit_cmd查询_Click
   
End Sub



Private Sub cmd清除_Click()
On Error GoTo Err_cmd清除_Click
    Dim ctl As Control
   
    For Each ctl In Me.Controls
   
        Select Case ctl.ControlType
            Case acTextBox
                If ctl.Locked = False Then ctl.Value = Null
               
            Case acComboBox
                ctl.Value = Null
        
        End Select
    Next
   
    '取消子窗体的筛选
    Me.全城区广告查询窗体.Form.Filter = ""
    Me.全城区广告查询窗体.Form.FilterOn = False
   
    Call CheckSubformCount

Exit_cmd清除_Click:
    Exit Sub

Err_cmd清除_Click:
    MsgBox Err.Description
    Resume Exit_cmd清除_Click
   
End Sub

Private Sub CheckSubformCount()

    If Me.存书查询子窗体.Form.Recordset.RecordCount > 0 Then
        '子窗体的记录数>0
        Me.计数.ControlSource = "=[全城区广告查询窗体].[Form].[txt计数]"
        Me.面积.ControlSource = "=[全城区广告查询窗体].[Form].[txt面积合计]"
    Else
        '子窗体的记录数=0
        Me.计数.ControlSource = "=0"
        Me.合计.ControlSource = "=0"
    End If  
End Sub

Private Sub 城区_afterupdate()
    Me.路段.RowSource = "select 路段,路段编号 from 城区路段表 where 城区='" & Me.城区 & "'"
End Sub

Private Sub 路段_AfterUpdate()
    Me.全城区广告查询窗体.Form.Filter = "路段编号='" & Me.路段 & "'"
    Me.全城区广告查询窗体.Form.FilterOn = True
End Sub
7#
 楼主| 发表于 2008-12-29 22:28:20 | 只看该作者
怎么没人理我啊,那位老师帮忙解决下啊
8#
发表于 2008-12-29 22:46:49 | 只看该作者
3楼链接里有个word文档你好好看看
9#
发表于 2008-12-30 07:06:10 | 只看该作者
6D老师这么早就来看帖,辛苦了[:49]
10#
 楼主| 发表于 2008-12-30 17:03:34 | 只看该作者
哎,搞了好久了,可这查询的代码还是没办法运行,谁帮我看看问题在哪啊?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-24 01:31 , Processed in 0.091515 second(s), 34 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表