以文本方式查看主题

-  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=30244)

--  作者:sadfox
--  发布时间:2013/3/23 18:24:00
--  求助,比较复杂的日期查询,狐爸来帮忙啊!

 

如图,下拉文本框中的选项对应表中的列。

1、需要不管是只输入年或者输入年和月,或者完整输入时间都能查询到对应列的日期.

2、同理。再增加个时间段的查询栏目,如1995-2013

3、查询没有时能出现提示,没有符合条件的数据。

只能求大神帮忙了,没相识的案列,希望大神能把代码注释写上,好学习一下。

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:7,(2).table


图片点击可在新窗口打开查看此主题相关图片如下:674.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2013-3-24 14:00:41编辑过]

--  作者:sadfox
--  发布时间:2013/3/23 20:43:00
--  
不能实现吗,如果可以,能不能再加个时间段的查询!
--  作者:sadfox
--  发布时间:2013/3/23 20:47:00
--  
郁闷是,为了搞这个,把项目都搞崩溃了,现在按ctrl都启动不了啦!
--  作者:lsy
--  发布时间:2013/3/23 21:32:00
--  
Dim t As Table = Tables("资料查询_资料查询")
Dim cmbtxt = e.Form.Controls("ComboBox1").Text
t.Filter = (cmbtxt & " = #" & e.Form.Controls("TextBox1").Text & "-" & e.Form.Controls("TextBox2").Text & "-" _
& e.Form.Controls("TextBox3").Text & "#")

--  作者:sadfox
--  发布时间:2013/3/23 21:49:00
--  
以下是引用lsy在2013-3-23 21:32:00的发言:
Dim t As Table = Tables("资料查询_资料查询")
Dim cmbtxt = e.Form.Controls("ComboBox1").Text
t.Filter = (cmbtxt & " = #" & e.Form.Controls("TextBox1").Text & "-" & e.Form.Controls("TextBox2").Text & "-" _
& e.Form.Controls("TextBox3").Text & "#")

引用,你这个只能输入完整的日期才能查询,如果只输入年份或者只输入年和月份就不能查询了


--  作者:e-png
--  发布时间:2013/3/23 22:40:00
--  

这样呢:?


Dim cnl As WinForm.ComboBox = Forms("资料查询").Controls("ComboBox1")
Dim tx1 As WinForm.TextBox = Forms("资料查询").Controls("TextBox1")
Dim tx2 As WinForm.TextBox = Forms("资料查询").Controls("TextBox2")
Dim tx3 As WinForm.TextBox = Forms("资料查询").Controls("TextBox3")
Dim t As Table = Tables("资料查询_资料查询")
Dim y As String
If tx2.text = ""
    y = "12"
Else
    y = tx2.text
End If
Dim yf As String = "4,6,9,11,04,06,09,11"
Dim dd,dd1 As String
If yf.contains(tx2.text) And tx1.text IsNot Nothing
    dd  = "30"
ElseIf Date.IsLeapYear(tx1.text) = True
    dd = "29"
ElseIf tx2.text = "2"
    dd = "28"
Else
    dd = "31"
End If
If tx3.text = ""
    dd1 = "1"
Else
    dd1 = tx3.text
End If

Dim cs As String = cnl.text &  " Like " & "\'" & tx1.text & "\'"

If cnl.text > "" And tx1.text > "" And tx2.text > "" And tx3.text > ""
    t.Filter = (cnl.text & " = #" & tx1.text & "-" & tx2.Text & "-" & tx3.Text & "#")

Else
    If cnl.text <> "" And tx1.text <> ""
        t.filter = " " & cnl.text & " > # " & dd1 & "/" & _
        y & "/" & tx1.text & "#  And  " & cnl.text & " < #" & _
        y & "/" & dd & "/" & tx1.text & "# "
    Else
        msgbox("请确认某日期或年份已经输入了")
    End If
End If

[此贴子已经被作者于2013-3-23 23:21:34编辑过]

--  作者:sadfox
--  发布时间:2013/3/23 23:38:00
--  
图片点击可在新窗口打开查看
e-png你的代码测试了下,只输入年份查可以了,但是在同时输入年份和月份的时候,月份时间没起作用,还是按年份查的
比如,我要查2013年9月退休人员,但是查询的结果却是2013年所有退休人员
[此贴子已经被作者于2013-3-23 23:39:38编辑过]

--  作者:lsy
--  发布时间:2013/3/23 23:46:00
--  

Dim t As Table = Tables("资料查询_资料查询")
Dim cmbtxt = e.Form.Controls("ComboBox1").Text
If e.Form.Controls("TextBox3").Text = "" Then
    t.Filter = cmbtxt & " > = #" & e.Form.Controls("TextBox1").Text & "-" & e.Form.Controls("TextBox2").Text & _
    "-01# And " & cmbtxt & " < = #" & e.Form.Controls("TextBox1").Text & "-" & e.Form.Controls("TextBox2").Text & "-28#"
ElseIf e.Form.Controls("TextBox2").Text = "" Then
    t.Filter = cmbtxt & " > = #" & e.Form.Controls("TextBox1").Text & "-01# And " & cmbtxt & " < = #" & e.Form.Controls("TextBox1").Text & "-12#"   
ElseIf e.Form.Controls("TextBox1").Text = "" Then
    t.Filter = ""
End If

 

只做了单一文本框为空的判断,而且没算完大小月、2月,基本思路是这样的,结果也是对的,你再把所有的可能性都过一遍,就行了,虽然有点笨,但管用。

真要做到滴水不漏,恐怕要用集合或数组来遍历所有可能性,年月日都要判断。

[此贴子已经被作者于2013-3-24 0:00:07编辑过]

--  作者:sadfox
--  发布时间:2013/3/24 0:09:00
--  
我是只老菜鸟+老白,才接触狐表学VB呢,现在才会点简单的,你的代码我基本上看不懂,辛苦你了,看来我还得等狐爸、大神了!
--  作者:e-png
--  发布时间:2013/3/24 0:22:00
--  

Dim cnl As WinForm.ComboBox = Forms("资料查询").Controls("ComboBox1")
Dim tx1 As WinForm.TextBox = Forms("资料查询").Controls("TextBox1")
Dim tx2 As WinForm.TextBox = Forms("资料查询").Controls("TextBox2")
Dim tx3 As WinForm.TextBox = Forms("资料查询").Controls("TextBox3")
Dim t As Table = Tables("资料查询_资料查询")
Dim y As String
If tx2.text = "" And tx3.text = ""
    y = "12"
ElseIf tx2.text = "" And tx3.text <> ""
    msgbox("少月份啦~")
    Return
Else
    y = tx2.text
End If
Dim yf As String = "4,6,9,11,04,06,09,11"
Dim dd,dd1 As String
If yf.contains(tx2.text) And tx1.text IsNot Nothing And tx2.text <> "1"
    dd  = "30"
ElseIf Date.IsLeapYear(tx1.text) = True And (tx2.text = "" Or tx2.text = "2")
    dd = "29"
ElseIf Date.IsLeapYear(tx1.text) = False And tx2.text = "2"
    dd = "28"
ElseIf tx2.text = "1"
    dd = "31"
Else
    dd = "31"
End If
If tx3.text = ""
    dd1 = "1"
Else
    dd1 = tx3.text
End If

 

If cnl.text > "" And tx1.text > "" And tx2.text > "" And tx3.text > ""
    t.Filter = (cnl.text & " = #" & tx1.text & "-" & tx2.Text & "-" & tx3.Text & "#")   
Else

        If cnl.text <> "" And tx1.text <> ""
        If tx1.text.length < 4
            msgbox("年份要4位数")
            Return 
        End If
        t.filter = " " & cnl.text & " > # " & dd1 & "/" & _
        y & "/" & tx1.text & "#  And  " & cnl.text & " < #" & _
        y & "/" & dd & "/" & tx1.text & "# "
    Else
        msgbox("请确认某日期或年份已经输入了")
    End If
End If