Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
楼主: danser

[已解决]运用窗体进行多个工作表的查询

[复制链接]
发表于 2014-1-25 17:55 | 显示全部楼层
  1.                 Set item = Me.ListView1.ListItems.Add(Text:=.Fields("盒号").Value)
  2.                 item.SubItems(2) = .Fields("位置").Value
  3.                 item.SubItems(1) = .Fields("订单号").Value
复制代码
改为
  1.             If Not IsNull(.Fields("盒号").Value) Then
  2.                 Set item = Me.ListView1.ListItems.Add(Text:=.Fields("盒号").Value)
  3.                 item.SubItems(2) = .Fields("位置").Value
  4.                 item.SubItems(1) = .Fields("订单号").Value
  5.             End If
复制代码
回复

使用道具 举报

 楼主| 发表于 2014-1-25 18:13 | 显示全部楼层
还是不能模糊查找,您再帮忙检查一下?谢谢啦{:191:}
回复

使用道具 举报

 楼主| 发表于 2014-1-26 09:47 | 显示全部楼层
hwc2ycy 发表于 2014-1-25 17:55
改为

hwc2ycy ,能帮忙看看吗?
回复

使用道具 举报

发表于 2014-1-26 10:03 | 显示全部楼层
danser 发表于 2014-1-26 09:47
hwc2ycy ,能帮忙看看吗?

模糊查找就要用LIKE来实现。


回复

使用道具 举报

发表于 2014-1-26 10:12 | 显示全部楼层
  1.             item.SubItems(2) = .Fields("位置").Value
  2.             item.SubItems(1) = .Fields("订单号").Value
复制代码
这里也要改,你没发现,你显示的内容跟标题不对嘛。
  1.             item.SubItems(1) = .Fields("位置").Value
  2.             item.SubItems(2) = .Fields("订单号").Value
复制代码
回复

使用道具 举报

 楼主| 发表于 2014-1-26 10:13 | 显示全部楼层
hwc2ycy 发表于 2014-1-26 10:03
模糊查找就要用LIKE来实现。

我用的是Like啊,不能模糊查找。
回复

使用道具 举报

发表于 2014-1-26 10:17 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub CommandButton1_Click()
  2.     Dim strFilter$
  3.     Dim item As ListItem
  4.    
  5.     If Len(Me.TextBox1.Value) = 1 And Me.TextBox1 Like "[!#]" Then
  6.         MsgBox "查找内容不符合要求,要求以数字开始!"
  7.         Me.TextBox1.Text = ""
  8.         Exit Sub
  9.     End If
  10.    
  11.     If Len(Me.TextBox1.Value) Then
  12.         strFilter = " and 订单号 like '" & Me.TextBox1.Value & "'" & strFilter
  13.     End If
  14.    
  15.     Me.ListView1.ListItems.Clear
  16.     With AdoRst
  17.         .Filter = ""
  18.         If Len(strFilter) Then
  19.             strFilter = Mid(strFilter, Len(" and ") + 1)
  20.         End If
  21.         .Filter = strFilter
  22.         If .RecordCount = 0 Then
  23.             MsgBox "无符合条件的记录"
  24.             Exit Sub
  25.         End If
  26.         Do While Not .EOF
  27.             If Not IsNull(.Fields("盒号")) Then
  28.             Set item = Me.ListView1.ListItems.Add(Text:=.Fields("盒号").Value)
  29.             item.SubItems(1) = .Fields("位置").Value
  30.             item.SubItems(2) = .Fields("订单号").Value
  31.             End If
  32.             .movenext
  33.         Loop
  34.     End With
  35. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2014-1-26 10:18 | 显示全部楼层
hwc2ycy 发表于 2014-1-26 10:12
这里也要改,你没发现,你显示的内容跟标题不对嘛。

这个我自己已经改过了,谢谢啦{:261:}
回复

使用道具 举报

发表于 2014-1-26 10:19 | 显示全部楼层
查找的内容要以数字开头,后面可以跟*,%,?这些通配符。
或者把查询语句改成
  1. strFilter = " and 订单号 like '*" & Me.TextBox1.Value & "*'" & strFilter
复制代码
回复

使用道具 举报

发表于 2014-1-26 10:21 | 显示全部楼层
  1. Private Sub CommandButton1_Click()
  2.     Dim strFilter$
  3.     Dim item As ListItem
  4.    
  5.     If Len(Me.TextBox1.Value) = 1 And Me.TextBox1 Like "[!0-9]" Then
  6.         MsgBox "查找内容不符合要求,要求以数字开始!"
  7.         Me.TextBox1.Text = ""
  8.         Exit Sub
  9.     End If
  10.    
  11.     If Len(Me.TextBox1.Value) Then
  12.         strFilter = " and 订单号 like '*" & Me.TextBox1.Value & "*'" & strFilter
  13.     End If
  14.    
  15.     Me.ListView1.ListItems.Clear
  16.     With AdoRst
  17.         .Filter = ""
  18.         If Len(strFilter) Then
  19.             strFilter = Mid(strFilter, Len(" and ") + 1)
  20.         End If
  21.         .Filter = strFilter
  22.         If .RecordCount = 0 Then
  23.             MsgBox "无符合条件的记录"
  24.             Exit Sub
  25.         End If
  26.         Do While Not .EOF
  27.             If Not IsNull(.Fields("盒号")) Then
  28.             Set item = Me.ListView1.ListItems.Add(Text:=.Fields("盒号").Value)
  29.             item.SubItems(1) = .Fields("位置").Value
  30.             item.SubItems(2) = .Fields("订单号").Value
  31.             End If
  32.             .movenext
  33.         Loop
  34.     End With
  35. End Sub
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-6 16:02 , Processed in 0.342378 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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