Office中国论坛/Access中国论坛

标题: 求救... [打印本页]

作者: cz3056    时间: 2011-7-13 14:22
标题: 求救...
Private Sub Command10_Click()
  On Error GoTo Err_Command10_Click
  Dim strWhere As String  '定义条件字符串
  strWhere = "" '设定初始值-空字符串
  
  '判断发货日期条件是否有输入值
  If Not IsNull(Me.Combo11) Then '有输入
    strWhere = strWhere & "([Combo11] like " & Me.Combo11 & ") AND "
  End If
  
  '判断物料名称条件是否有输入值
  If Not IsNull(Me.Combo7) Then '有输入
    strWhere = strWhere & "([Combo7] like " & Me.Combo7 & ") AND "
  End If
  
  '判断发往单位条件是否有输入值
  If Not IsNull(Me.Combo5) Then '有输入
    strWhere = strWhere & "([Combo5] like " & Me.Combo5 & ") AND "
  End If
  
  '如果输入了条件,那么strWhere的最后肯定有" AND ",这是我们不需要的,要用LEFT函数截掉这5个字符。
  If Len(strWhere) > 0 Then '有输入条件
    strWhere = Left(strWhere, Len(strWhere) - 5)
  End If
  
  '先在立即窗口显示一下strWhere的值,代码调试完成后可以取消下一句
  Debug.Print strWhere
  
  '让子窗体应用窗体查询
  Me.发出物料信息查询表.Form.Filter = strWhere
  Me.发出物料信息查询表.Form.FilterOn = True
  
  '在子窗体筛选后要运行一下自编子程序CheckSubformCount()
  'Call CheckSubformCount
  
Exit_Command10_Click:
  Exit Sub
  
Err_Command10_Click:
  MsgBox Err.Description
  Resume Exit_Command10_Click
  
End Sub


为什么按这个做了之后,查询出来的结果却是全部数据呢??

作者: 轻风    时间: 2011-7-13 16:12
不会吧,再仔细检查一下你输入的条件。或者上传实例
作者: cz3056    时间: 2011-7-13 16:35
[attach]46078[/attach]
作者: todaynew    时间: 2011-7-13 17:09
本帖最后由 todaynew 于 2011-7-13 17:13 编辑
cz3056 发表于 2011-7-13 16:35

1、组合框的值只与绑定列有关,与其显示的内容有时候无关。
2、可将筛选的初值赋值为"True",这样可以简化代码。

Private Sub Command2_Click()
Dim strWhere As String
strWhere = "True"
If Not IsNull(Me.信息) Then
    strWhere = strWhere & " and 编号=" & Me.信息.Value
End If
Me.信息查询子窗体.Form.Filter = strWhere
Me.信息查询子窗体.Form.FilterOn = True
End Sub

作者: yanghua1900363    时间: 2011-7-29 18:35
学习了




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