设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

123
返回列表 发新帖
楼主: yanwei82123300
打印 上一主题 下一主题

[模块/函数] 公司的工厂日历的模块代码,进行修改规整

[复制链接]
21#
发表于 2010-10-12 08:50:57 | 只看该作者
todaynew 老师我要提取日期的目的是将客户订单的需求日期与这个日期做链接目的是:1、看订单落在哪一个月? ...
yanwei82123300 发表于 2010-10-12 08:12

最后的示例中已经给你写了两个函数,其中mnth函数就是用来返回相应数据的。

Function Calendar(Myyear As Long) As String
'功能:每季度按445周的的工厂日历
'参数:Myyear--财政年度
'示例:Me.日历.RowSource = "月度;首日;末日;" & Calendar(Me.年度.Value)
Dim mydate As Date
Dim str As String
Dim i As Long, j As Long, m
mydate = DateSerial(Myyear - 1, 10, 1)
str = str & 1 & ";" & mydate & ";"
If Weekday(mydate, vbMonday) <> 6 Then
    mydate = DateAdd("d", 21, mydate)
    For j = 1 To 7
        If Weekday(mydate, vbMonday) = 5 Then
                Exit For
        End If
        mydate = DateAdd("d", 1, mydate)
    Next
Else
    mydate = DateAdd("d", 20, mydate)
End If
str = str & mydate & ";"
m = 0
For i = 1 To 4
    For j = 1 To 3
        m = m + 1
        If m = 12 Then Exit For
        If m <> 1 Then
            str = str & m & ";" & DateAdd("d", 1, mydate) & ";"
            If j <> 3 Then
                mydate = DateAdd("d", 28, mydate)
            Else
                mydate = DateAdd("d", 35, mydate)
            End If
            str = str & mydate & ";"
        End If
    Next
    If m = 12 Then Exit For
Next
str = str & m & ";" & DateAdd("d", 1, mydate) & ";" & DateSerial(Myyear, 9, 30)
Calendar = str
End Function

Function mnth(mydate As Date) As Variant
'功能:按日历日期返回财政日历数组
'参数:mydate--日历日期
'示例:
'
'select *,mnth(订单日期)(0) as 财政年,mnth(订单日期)(1) as 财政月,mnth(订单日期)(4) as 周 from 订单表
Dim str As String
Dim myMonth As Long
Dim A
Dim B(5)
Dim date0 As Date, date1 As Date
Dim i As Long
If Month(mydate) >= 10 And Month(mydate) <= 12 Then
    str = Calendar(Year(mydate) + 1)
    B(0) = Year(mydate) + 1
Else
    str = Calendar(Year(mydate))
    B(0) = Year(mydate)
End If
A = Split(str, ";")
For i = 0 To UBound(A, 1) Step 3
    myMonth = A(i)
    date0 = CDate(A(i + 1))
    date1 = CDate(A(i + 2))
    If CDate(mydate) >= date0 And CDate(mydate) <= date1 Then
        B(2) = date0: B(3) = date1
        B(4) = DateDiff("ww", date0, mydate)
        Exit For
    End If
Next
B(1) = myMonth
mnth = B
End Function



22#
 楼主| 发表于 2010-10-12 10:02:42 | 只看该作者
非常谢谢todaynew 帮助!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-17 03:29 , Processed in 0.070242 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表