Foxtable(狐表)用户栏目专家坐堂 → [求助]我这个查询条件,怎么没有效果?帮忙看看怎么回事,谢谢


  共有4450人关注过本帖树形打印复制链接

主题:[求助]我这个查询条件,怎么没有效果?帮忙看看怎么回事,谢谢

帅哥哟,离线,有人找我吗?
lsy
  11楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:5246 积分:33163 威望:0 精华:8 注册:2013/1/17 21:28:00
  发帖心情 Post By:2014/2/27 15:10:00 [只看该作者]

楼主把例子发上来,几行代码就行了。

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  12楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251397 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2014/2/27 15:12:00 [只看该作者]

计算机是最机械的,是不会撒谎的,说找不到这列,那肯定就不存在"danjuzhuangtai"这一列。

看看自己是不是把列名和列标题搞混了,搞不定就做个简单例子发上来。

 

 

[此贴子已经被作者于2014-2-27 15:13:11编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
aduydgd
  13楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:681 积分:5332 威望:0 精华:0 注册:2011/12/26 20:43:00
  发帖心情 Post By:2014/2/27 15:13:00 [只看该作者]

1.这是生成的表

Select  [bianhao_ID] As [编号],jieshoudanwei As [接收机构],jieshouren As [接收人],laiyuanjing As [来源机构],[sx_danwei] As [送修单位],[sx_ren] As [送修人],[sx_riqi] As [送修日期],[sx_wuliu] As [送修物流],[sx_wuliu_d] As [送修物流单号],jieshouriqi As [接收日期],[chanpin_xinghao] As [产品型号],pinpai As [品牌],chanpindalei As [产品大类],jixin As [机芯],jihao As [机号],chanpinleibie As [产品类别],zichanshuxing As [资产属性],baoxiuxingzhi As [保修性质],[gz_xianxiang] As [故障现象],beijianxinghao As [屏型号],chuchangriqi As [出厂日期],danjuzhuangtai As [单据状态],[pai_riqi] As [派工日期],[pai_ren] As [派工人],[wx_hj] As [维修环节],weixiuzhuangtai As [维修状态],[wx_ren] As [维修人],beizhu As [备注] From {Main_table}  order by bianhao_ID ASC

 

2.这是查询条件

Dim Filter As String
With e.Form.Controls("jieshou")
    If .Value IsNot Nothing Then
        Filter = "jieshoudanwei = '" & .Value & "'"
    End If
End With
With e.Form.Controls("laiyuan")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "laiyuanjing = '" & .Value & "'"
    End If
End With
With e.Form.Controls("danju")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "danjuzhuangtai = '" & .Value & "'"
    End If
End With
With e.Form.Controls("weixiu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "weixiuzhuangtai = '" & .Value & "'"
    End If
End With
With e.Form.Controls("chanpin")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "chanpin_xinghao = '" & .Value & "'"
    End If
End With
With e.Form.Controls("jihao")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "jihao = '" & .Value & "'"
    End If
End With
If e.Form.Controls("sxriqi").Checked = True
    With e.Form.Controls("kai")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "sx_riqi >= #" & .Value & "#"
        End If
    End With
End If
With e.Form.Controls("jieshu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "sx_riqi <= #" & .Value & "#"
    End If
End With
If e.Form.Controls("jieriqi").Checked = True
    With e.Form.Controls("kai")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "jieshouriqi >= #" & .Value & "#"
        End If
    End With
End If
With e.Form.Controls("jieshu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "jieshouriqi <= #" & .Value & "#"
    End If
End With
If e.Form.Controls("pairiqi").Checked = True
    With e.Form.Controls("kai")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "pai_riqi >= #" & .Value & "#"
        End If
    End With
End If
With e.Form.Controls("jieshu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "pai_riqi <= #" & .Value & "#"
    End If
End With
If e.Form.Controls("huiriqi").Checked = True
    With e.Form.Controls("kai")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "weixiuriqi >= #" & .Value & "#"
        End If
    End With
End If
With e.Form.Controls("jieshu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "weixiuriqi <= #" & .Value & "#"
    End If
End With
If Filter > "" Then
    Tables("信息追踪_table1").Filter = Filter
End If

 

3.错误提示

在9楼

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  14楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/2/27 15:15:00 [只看该作者]

你不是都全部重命名了嘛, 那就应该使用重命名后的名称.

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  15楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251397 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2014/2/27 15:15:00 [只看该作者]

例如:

 

baoxiuxingzhi As [保修性质]

 

现在的列名是“保修性质",不是"baoxiuxingzhi"

 

你这是筛选,处理的是已经加载进来的数据,全部按照新的列名调整你的代码。

[此贴子已经被作者于2014-2-27 15:15:37编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
aduydgd
  16楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:681 积分:5332 威望:0 精华:0 注册:2011/12/26 20:43:00
  发帖心情 Post By:2014/2/27 15:24:00 [只看该作者]

真是这样的问题,之前没有理解清除,现在可以了,郁闷死我了,真是谢谢大家了


 回到顶部
帅哥哟,离线,有人找我吗?
lsy
  17楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:5246 积分:33163 威望:0 精华:8 注册:2013/1/17 21:28:00
  发帖心情 Post By:2014/2/27 15:38:00 [只看该作者]

多列筛选,如果是几十列,还不累坏了。

不能简单罗列,还是用循环,不管多少列,也不管列名如何变、数据类型如何变,代码都是不变的。

Dim flt As String
For Each c As Col In Tables("光缆台帐表").Cols
    For Each ctl As WinForm.Control In e.Form.Controls
        If ctl.Name.Contains(c.Name) AndAlso e.Form.Controls(ctl.Name).Value <> Nothing Then
            If c.IsString Then
                flt + = " And " & c.Name & " Like '%" & e.Form.Controls(ctl.Name).Value & "%'"
            ElseIf c.IsNumeric Then
                flt + = " And " & c.Name & " = " & e.Form.Controls(ctl.Name).Value
            ElseIf c.IsBoolean Then
                flt + = " And " & c.Name & " = " & e.Form.Controls(ctl.Name).Checked
            ElseIf c.IsDate Then
                If ctl.Name.Contains("Start") Then
                    flt + = " And " & c.Name & " >= #" & e.Form.Controls(ctl.Name).Value & "#"
                ElseIf ctl.Name.Contains("End") Then
                    flt + = " And " & c.Name & " <= #" & e.Form.Controls(ctl.Name).Value & "#"
                End If
            End If
        End If
    Next
Next
If flt > "" Then
    flt = flt.SubString(5)
Else
    MessageBox.Show("请输入查询条件")
End If
Tables("光缆台帐表").Filter = flt

[此贴子已经被作者于2014-2-27 15:39:19编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
aduydgd
  18楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:681 积分:5332 威望:0 精华:0 注册:2011/12/26 20:43:00
  发帖心情 Post By:2014/2/27 15:44:00 [只看该作者]

这么简单啊,我试试

 回到顶部
总数 18 上一页 1 2