标题: 查询代码如何填写 [打印本页] 作者: jp777 时间: 2009-7-7 11:40 标题: 查询代码如何填写 论坛里面关于查询代码的例子多如浩海,我的水平有限,于是将自己看的懂的一些查询代码合成了一个例子.但总是报错.希望高手能够帮助解答一下.另外是否能推荐一些相关的书籍的.谢谢
Private Sub CmdQuery_Click()
Dim strWhere As String
strWhere = "True"
If Nz(Me.SAP_No, "") <> "" Then strWhere = strWhere & " AND [SAP No] Like ""*" & Me.SAP_No & "*"""
If Nz(Me.Storage_bin, "") <> "" Then strWhere = strWhere & " AND [Storage bin] Like ""*" & Me.Storage_bin & "*"""
If Nz(Me.Material, "") <> "" Then strWhere = strWhere & " AND [Material] Like ""*" & Me.Material & "*"""
If Nz(Me.Spec, "") <> "" Then strWhere = strWhere & " AND [Spec] Like ""*" & Me.Spec & "*"""
If Nz(Me.Starting_Time, "") <> "" Then strWhere = strWhere & "([Starting Time] >= #" & Format(Me.Starting_Time, "yyyy-mm-dd") & "#) AND "
If Nz(Me.Closing_Time, "") <> "" Then strWhere = strWhere & "([Closing Time] <= #" & Format(Me.Closing_Time, "yyyy-mm-dd") & "#) AND "
If Len(strWhere) > 5 Then
Me.Showlist.RowSource = "SELECT * FROM Receiving WHERE " & strWhere
End If
End Sub
[attach]38794[/attach]作者: jp777 时间: 2009-7-7 21:01
有人能帮助我吗?谢谢。