Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

可否将窗体中输入的年.月格式中的年提取出来做条件进行查询?

phenix  发表于:2010-08-22 01:54:44  
复制

有如下代码,[参加工作时间]、[转出时间]等窗体上文本框在输入的时候都是采用4位年的格式,表和查询中也都以4位年为依据进行工作,如果我要在窗体中输入例如2000.7这样的日期格式,能否在查询的时候自动取2000为查询的条件?谢谢。

 

Private Sub cmd工资查询_Click()
    Dim strWhere As String
    Dim str(1 To 3) As String

    Dim b As Boolean
    b = IsNull(Me.xueli) And IsNull(Me.cjgzsj) And IsNull(Me.zcsj)
    If b = True Then
        strWhere = "False"
    Else
        strWhere = "True"
    End If

    If Not IsNull(Me.xueli) Then
        strWhere = strWhere & " AND ([学历] like '" & Me.xueli & "')"
    End If
   
    If Not IsNull(Me.cjgzsj) Then
        strWhere = strWhere & " AND ([参加工作时间] like '" & Me.cjgzsj & "')"
    End If

    If Not IsNull(Me.zcsj) Then
        str(1) = strWhere & " AND ([转出时间] = " & Me.cjgzsj & ")"
        str(2) = strWhere & " AND ([转出时间] = " & Me.cjgzsj & "+1)"
        str(3) = strWhere & " AND ([转出时间]> " & Me.cjgzsj & "+1 And [转出时间]<=" & Me.zcsj & ")"
    End If

   
    Me.试用期子窗体.Form.Filter = str(1)
    Me.试用期子窗体.Form.FilterOn = True
   
    Me.转正定级子窗体.Form.Filter = str(2)
    Me.转正定级子窗体.Form.FilterOn = True
   
    Me.晋升子窗体.Form.Filter = str(3)
    Me.晋升子窗体.Form.FilterOn = True

End Sub

 

Top
老鬼 发表于:2010-08-22 10:11:18

用year(日期)函数,应该可以将日期变成年度。



phenix 发表于:2010-08-22 11:14:02

正如老鬼所说,我刚刚用year函数解决了,虽然是自己蒙对的,但和老鬼朋友的方法一致,所以最佳给老鬼朋友了,非常感谢。

 

修改后的代码如下:

 

Private Sub cmd工资查询_Click()
    Dim strWhere As String
    Dim str(1 To 3) As String

        strWhere = "True"

    If Not IsNull(Me.xueli) Then
        strWhere = strWhere & " AND ([学历] like '" & Me.xueli & "')"
    End If
   
    If Not IsNull(Me.cjgzsj) Then
        strWhere = strWhere & " AND ([参加工作时间] like '" & Year(Me.cjgzsj) & "')"
    End If

    If Not IsNull(Me.zcsj) Then
        str(1) = strWhere & " AND ([转出时间] = " & Year(Me.cjgzsj) & ")"
        str(2) = strWhere & " AND ([转出时间] = " & Year(Me.cjgzsj) & "+1)"
        str(3) = strWhere & " AND ([转出时间]> " & Year(Me.cjgzsj) & "+1 And [转出时间]<=" & Year(Me.zcsj) & ")"
    End If

    Me.试用期子窗体.Form.Filter = str(1)
    Me.试用期子窗体.Form.FilterOn = True
   
    Me.转正定级子窗体.Form.Filter = str(2)
    Me.转正定级子窗体.Form.FilterOn = True
   
    Me.晋升子窗体.Form.Filter = str(3)
    Me.晋升子窗体.Form.FilterOn = True

End Sub



总记录:2篇  页次:1/1 9 1 :