Office中国论坛/Access中国论坛

标题: 控件查询子窗体的问题 [打印本页]

作者: benvicky    时间: 2010-5-20 10:40
标题: 控件查询子窗体的问题
我是新人,做了个查询窗口,但是现在设置筛选字符串的时候
出现问题,请问问题在哪里啊??[attach]42252[/attach]
作者: benvicky    时间: 2010-5-20 15:18
我看了一天了,在网上查来查去都没看出问题根源
好像问题出在
Me.[申贷项目_子窗体].Form.Filter = strWhere
Me.[申贷项目_子窗体].Form.FilterOn = True
Call CheckSubformCount
请好心人再帮我看下   新附件如下[attach]42257[/attach]
作者: fnsmydyang    时间: 2010-5-20 22:24
因你的附件上没有后台数据库,所以没有办法给你调试,问题是出在筛选条件上,你是借用了刘小军多条件查询一段代码,可惜你没有真正理解,你的条件多了5个字符串,要去掉.
修改一下:
Private Sub cmd查询_Click()
On Error GoTo Err_cmd查询_Click
Dim strWhere As String
strWhere = ""
    If Not IsNull(Me.name) Then
        strWhere = strWhere & "([企业名称] like '*" & Me.name & "*') AND "
    End If
    If Not IsNull(Me.leibie) Then
        strWhere = strWhere & "([项目类别] like '*" & Me.leibie & "*') AND "
    End If
   
    If Not IsNull(Me.adress) Then
        strWhere = strWhere & "([项目地点] like '*" & Me.adress & "*') AND "
    End If
   
    If Not IsNull(Me.from) Then
        strWhere = strWhere & "([来源渠道] like '*" & Me.from & "*') AND "
    End If
   
    If Not IsNull(Me.startmoney) Then
        strWhere = strWhere & "([融资金额] >= " & Me.startmoney & ") AND "
    End If
   
    If Not IsNull(Me.endmoney) Then
        strWhere = strWhere & "([融资金额] <= " & Me.endmoney & ") AND "
    End If
    If Not IsNull(Me.starttime) Then
        strWhere = strWhere & "([申请时间] >= #" & Format(Me.starttime, "yyyy-mm-dd") & "#) AND "
    End If
    If Not IsNull(Me.endtime) Then
        strWhere = strWhere & "([申请时间] <= #" & Format(Me.endtime, "yyyy-mm-dd") & "#) AND "
    End If
    'Debug.Print strWhere
    If Len(strWhere) > 0 Then
        '有输入条件
        strWhere = Left(strWhere, Len(strWhere) - 5)
    End If

   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
作者: qmyjhj    时间: 2010-5-23 17:36
是啊,尤其要注意筛选条件字符串的格式,很多错误都出现在这里
你的那两句代码是没有问题的




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