Office中国论坛/Access中国论坛

标题: 求助IN语句的查询问题 [打印本页]

作者: 毒舌    时间: 2006-11-21 02:56
标题: 求助IN语句的查询问题
[attach]21610[/attach]


Private Sub Command2_Click()
If Not IsNull(Me.名称1) Then
   StrWhere = Mid(Me.名称1, 1, Len(Me.名称1) - 1)
End If



'Debug.Print StrWhere



Me.表1查询子窗体.Form.Filter = "[名称] in (" & StrWhere & ")"
Me.表1查询子窗体.Form.FilterOn = True
End Sub




这个是按照andymark的代码修改的,可是这个代码只能能查询数据类型为"数字"的字段~但是怎么改才能可以查询数据类型为文本的文字和字母数字组合啊?

以上谢谢
作者: coolbug    时间: 2006-11-21 07:39
如果定义filter的值,可能需要完整的SQL语句,最好把这个加到子窗体的SQL的where条件中,另外需要在strwhere两端加上"'"& strwhere & "'",以便和string字符匹配.
作者: 浩雨    时间: 2006-11-21 16:27
Private Sub Command2_Click()
If Not IsNull(Me.名称1) Then
   StrWhere = Mid(Me.名称1, 1, Len(Me.名称1) - 1)
End If

Debug.Print StrWhere

Me.表1查询子窗体.Form.Filter = "[名称] in ('" & StrWhere & "')"
Me.表1查询子窗体.Form.FilterOn = True
End Sub
作者: 毒舌    时间: 2006-11-22 03:40
谢谢楼上2位的回复~

但是改成

Private Sub Command2_Click()
If Not IsNull(Me.名称1) Then
   StrWhere = Mid(Me.名称1, 1, Len(Me.名称1) - 1)
End If



Debug.Print StrWhere



Me.表1查询子窗体.Form.Filter = "[名称] in ('" & StrWhere & "')"
Me.表1查询子窗体.Form.FilterOn = True
End Sub



后就只能查询一个了~而不是多个同时查询
作者: 浩雨    时间: 2006-11-22 10:42
供参考:[attach]21648[/attach]

作者: 毒舌    时间: 2006-11-23 01:31
十分感谢~



鞠躬




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