|
本帖最后由 sunw1984 于 2017-7-14 15:02 编辑
本人初用ACCESS菜鸟,套用论坛里的一些代码和教程实现了多条件查询,但是最后有一个条件不知道怎么搞,特请高手不吝赐教
如图(在查询代码下面),想实现“出入库”下拉菜单查询,如下拉选择“入库”,则子窗体中“总重量_kg”显示全部大于0条目;反之,如果选择“出库”,则子窗体中“总重量_kg”显示全部小于0的条目;
请教大家怎么增加查询代码,现有查询代码如下:
- Private Sub cmd查询_Click()
- On Error GoTo Err_cmd查询_Click
- Dim strWhere As String
- strWhere = ""
- If Not IsNull(Me.库位) Then
- strWhere = strWhere & "([库位] like '*" & Me.库位 & "*') AND "
- End If
- If Not IsNull(Me.包装形式) Then
- strWhere = strWhere & "([包装形式] like '" & Me.包装形式 & "') AND "
- End If
- If Not IsNull(Me.品种) Then
- strWhere = strWhere & "([品种] like '*" & Me.品种 & "*') AND "
- End If
- If Not IsNull(Me.生产批号) Then
- strWhere = strWhere & "([生产批号] like '" & Me.生产批号 & "') AND "
- End If
- If Not IsNull(Me.包装批号) Then
- strWhere = strWhere & "([包装批号] like '" & Me.包装批号 & "') AND "
- End If
- If Not IsNull(Me.开始日期) Then
- strWhere = strWhere & "([日期] >= #" & Format(Me.开始日期, "yyyy-mm-dd") & "#) AND "
- End If
- If Not IsNull(Me.截止日期) Then
- strWhere = strWhere & "([日期] <= #" & Format(Me.截止日期, "yyyy-mm-dd") & "#) AND "
- End If
-
- If Len(strWhere) > 0 Then
- strWhere = Left(strWhere, Len(strWhere) - 5)
- End If
- Debug.Print strWhere
- 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
复制代码 |
|