Office中国论坛/Access中国论坛

标题: 求助窗体联动的多条件选择查询? [打印本页]

作者: htlsb    时间: 2008-12-29 00:18
标题: 求助窗体联动的多条件选择查询?
我做了个查询,在查询窗体中想实现实现1个或者多个条件选择查询,我些了查询的语句,可加入后没办法实现,所以我就把语句放在TXT文件里了,请求各位老师帮忙!!!!
[

[ 本帖最后由 htlsb 于 2009-1-1 00:26 编辑 ]
作者: htlsb    时间: 2008-12-29 00:20
如果能在TXT里加点简易的实现的解释方便我理解更好!
作者: Henry D. Sy    时间: 2008-12-29 04:01
http://www.accessbbs.cn/bbs/thread-9356-1-1.html
作者: htlsb    时间: 2008-12-29 12:59
我就是学习刘大的查询1做的 ,不过不知道什么原因,查询语句写进查询条件就出问题查询的子窗体也不引用了
作者: WANGDUYU    时间: 2008-12-29 13:32
看了一下,有一点想法,不知道对不对,您可以先试一试。
您写的代码里,引用了窗体的Requery属性,不知道窗体对象有没有Requery的属性。如果有可能,还是应该先把子窗体的查询requery一下,之后再使用子窗体,这样比较稳妥。
作者: htlsb    时间: 2008-12-29 14: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
作者: htlsb    时间: 2008-12-29 22:28
怎么没人理我啊,那位老师帮忙解决下啊
作者: Henry D. Sy    时间: 2008-12-29 22:46
3楼链接里有个word文档你好好看看
作者: fnsmydyang    时间: 2008-12-30 07:06
6D老师这么早就来看帖,辛苦了[:49]
作者: htlsb    时间: 2008-12-30 17:03
哎,搞了好久了,可这查询的代码还是没办法运行,谁帮我看看问题在哪啊?
作者: manken    时间: 2009-8-14 14:44
咋就没有人给解决呢?
作者: weizexon    时间: 2009-9-11 04:06
来学习下~




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3