以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  日期转换成字符串后,能否截取字段?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=15918)

--  作者:jk245610644
--  发布时间:2012/1/18 8:55:00
--  日期转换成字符串后,能否截取字段?

合同号是根据日期来订的,比如2011年09月签的合同,合同号即为:1109*****

想通过一个时间段进行筛选。即通过输入开始时间,结束时间对合同号进行筛选。

这是我筛选代码中相关的一段:

With e.Form.Controls("Start")   \'开始日期的控件
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "e.row(合同号).substring(0,4) >= cstr(#" & .Value & "#).substring(2,4)"
    End If
End With
With e.Form.Controls("End")    \'结束日期的控件\'
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "e.row(合同号) <= cstr(#" & .Value & "#).substring(2,4)"
    End If
End With

 

错误:包含未定义的函数调用 e.Row()

[此贴子已经被作者于2012-1-18 9:09:31编辑过]

--  作者:狐狸爸爸
--  发布时间:2012/1/18 11:24:00
--  

1、你的代码用在什么事件中,这个事件有e.row这个参数吗?

2、即使用e.row这个参数,也不是这样用的,正常的筛选,必须通过列名。

 

你的代码的错误有些离谱,你学了很多,但是不踏实,是跑步前进,才会写出这样的代码,建议你从头细看帮助两遍,从使用指南开始看。

 

正常的代码,大概是:

 

Dim Filter As String
With e.Form.Controls("Start")   \'开始日期的控件
    If .Value IsNot Nothing Then
        Dim s As String = .value
        Filter =  "Substring(合同号1,4) >= \'" & s.Substring(0,4) & "\'"
    End If
End With
With e.Form.Controls("End")    \'结束日期的控件\'
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Dim s As String = .value
        Filter = Filter & "Substring(合同号1,4) <= \'" & s.Substring(0,4) & "\'"
    End If
End With

Tables("XXX").Filter = Filter

 

 

[此贴子已经被作者于2012-1-18 11:24:47编辑过]