Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MS Access VBA-do-TILL循环期间系统崩溃_Vba_Ms Access - Fatal编程技术网

MS Access VBA-do-TILL循环期间系统崩溃

MS Access VBA-do-TILL循环期间系统崩溃,vba,ms-access,Vba,Ms Access,我试图在表格上计算两个日期之间的天数,不包括周末。但是,每次运行do-until循环时,系统都会不断崩溃。你能在下面的代码中找出我可能出错的地方吗 谢谢你的帮助 Private Sub total_text_Click() Dim v_weekendcount As Integer Dim v_date As Date Dim dateone As Date Dim datetwo As Date v_date = Me.startdate_text.Value v_weekendcount

我试图在表格上计算两个日期之间的天数,不包括周末。但是,每次运行do-until循环时,系统都会不断崩溃。你能在下面的代码中找出我可能出错的地方吗

谢谢你的帮助

Private Sub total_text_Click()
Dim v_weekendcount As Integer
Dim v_date As Date
Dim dateone As Date
Dim datetwo As Date

v_date = Me.startdate_text.Value
v_weekendcount = 0

Do Until v_date = Me.enddate_text.Value
If Day(v_date) = vbSaturday Or Day(v_date) = vbSunday Then
v_weekendcount = v_weekendcount + 1
v_date = v_date + 1
End If
Loop

dateone = Me.startdate_text.Value
datetwo = Me.enddate_text.Value

Me.total_text.Value = DateDiff("d", dateone, datetwo) - v_weekendcount

End Sub

为了排除这种可能性,请相应更改以下行:

If (Day(v_date) = vbSaturday) Or (Day(v_date) = vbSunday) Then

您在周末支票内有v_date=v_date+1个电话。这难道不意味着当不是周末时,它不会增加日期吗?

您可能已经想到了这一点:

Do Until v_date = DateValue(Me.enddate_text.Value)
    If Weekday(v_date) = vbSaturday Or Weekday(v_date) = vbSunday Then
        v_weekendcount = v_weekendcount + 1
    End If
    v_date = v_date + 1
Loop

这就是为什么嵌套
IF
语句、
Do
语句和每个
语句的
非常重要的原因。如果做了正确的嵌套,这将是更明显的错误谢谢,这阻止了系统崩溃!然而,出于某种原因,它并没有将周末排除在总天数计算之外。你能看到是什么导致了这个问题吗?