设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[查询] 查询遗漏的日期

[复制链接]
11#
 楼主| 发表于 2013-8-29 13:30:03 | 只看该作者

经过摸索,应该是这样的,我明白了。谢谢论坛里的各位老大的指点!
Private Sub 年度_AfterUpdate()
    If IsNull(Me.年度.Value) = False And IsNull(Me.月度.Value) = False Then
        Me.遗漏日期.RowSource = GetDateList(Me.年度.Value, Me.月度.Value, "数据表", "日期")
    End If
End Sub

Private Sub 月度_AfterUpdate()
    If IsNull(Me.年度.Value) = False And IsNull(Me.月度.Value) = False Then
        Me.遗漏日期.RowSource = GetDateList(Me.年度.Value, Me.月度.Value, "数据表", "日期")
    End If
End Sub

Function GetDateList(ByVal y As Long, ByVal m As Long, ByVal tbname As String, DateFildname As String) As String


    Dim str As String
    Dim ssql As String
    Dim i As Long
    Dim d0 As Date
    Dim d1 As Date
   
    ssql = "select * from " & tbname & " where year(" & DateFildname & ")=" & y & " and month(" & DateFildname & ")=" & m

    Me.数据表.RowSource = ssql

   
    If Year(Date) = y And Month(Date) = m Then
        d1 = Date
    Else
        d1 = DateSerial(y, m + 1, 0)
    End If
   
    str = ""
    d0 = DateSerial(y, m, 1)
    Do While d0 <= d1
        If DCount("*", "" & tbname & "", "日期=#" & d0 & "#") = 0 Then
            str = str & d0 & ";"
        End If
        d0 = DateAdd("d", 1, d0)
    Loop
    str = Left(str, Len(str) - 1)
    GetDateList = str
End Function
12#
 楼主| 发表于 2013-9-28 18:30:49 | 只看该作者


经过一段时间的使用,的确可以检查遗漏的日期,但存在一个问题,如果没有遗漏的日期,就会出现提示框,提示运行错误需要调试,能否不不出现提示框,遗漏日期列表框中显示空白就行了,请高手指点,谢谢!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
13#
 楼主| 发表于 2013-9-28 18:40:32 | 只看该作者
str = Left(str, Len(str) - 0)
我知道了,要修改这一句,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-19 08:31 , Processed in 0.085825 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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