Dim dt As Date
dt = e.Form.Controls("DateTimePicker1").Value
If e.Form.Controls("CheckBox_quxiao").Checked Then
Tables("客户及订单_table_dingdan").Filter = "[日期] =' " & dt & "'"
Else
Tables("客户及订单_table_dingdan").Filter = "[日期] =' " & dt & "' And ([状态] <> '取消' or [状态] Is Null) "
End If
Tables("客户及订单_table_dingdan").sort = "产品,酒店 DESC"
Dim todaybeizhu As String
todaybeizhu = e.Form.Controls("DateTimePicker1").Value & ",总人数:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "") & "人,关外:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 = '关外'") & _
"人,镇上外店:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 <> '自驾' and 酒店 <> '关外' and 酒店 <> '皇冠' and 酒店 <> '蓝景' and 酒店 <> '希尔顿'and 酒店 <> '黄松浦' and 酒店 <> '山门' and 酒店 <> '半山' ") & _
"人,山门:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 = '皇冠' or 酒店 = '蓝景' or 酒店 = '希尔顿' or 酒店 = '黄松浦' or 酒店 = '山门' or 酒店 = '半山' ") & _
"人,自驾:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 = '自驾'") & _
"人,其他:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 is null ")
e.Form.Controls("TextBox4").value = todaybeizhu
Dim dr As DataRow
dr = DataTables("日汇总表").Find("[日期] = '" & e.Form.Controls("DateTimePicker1").Value & "'", "日期 Desc")
If dr IsNot Nothing Then
Dim wz As Integer = Tables("日汇总表").FindRow(dr)
If wz >= 0 Then
Tables("日汇总表").Position = wz
End If
Else
Tables("日汇总表").AddNew
Tables("日汇总表").current("日期") = e.Form.Controls("DateTimePicker1").Value
Tables("日汇总表").current("当日备注") = todaybeizhu '
End If
日期值有多余的空格去掉:
If e.Form.Controls("CheckBox_quxiao").Checked Then
Tables("客户及订单_table_dingdan").Filter = "[日期] =' " & dt & "'"
Else
Tables("客户及订单_table_dingdan").Filter = "[日期] =' " & dt & "' And ([状态] <> '取消' or [状态] Is Null) "
End If
调试对比看看就明白了
msgbox("[日期] ='" & dt & "'")
msgbox("[日期] =' " & dt & "'")
另外,筛选日期值最好使用#符号
If e.Form.Controls("CheckBox_quxiao").Checked Then
Tables("客户及订单_table_dingdan").Filter = "[日期] =#" & dt & "#"
Else
Tables("客户及订单_table_dingdan").Filter = "[日期] =#" & dt & "# And ([状态] <> '取消' or [状态] Is Null) "
End If
可能是窗口load时, e.Form.Controls("DateTimePicker1").Value是空值。
-----------------------------------------------------------------
改成 # 的代码,提示以下错误。
.NET Framework 版本:4.0.30319.233
Foxtable 版本:2025.1.3.1
错误所在事件:窗口,客户及订单,DateTimePicker1,ValueChanged
详细错误信息:
表达式包含无效的日期常量“##”。
---------------------------------------------------------------------
如果是 ‘ ,就提示之前的那种错误。
.NET Framework 版本:4.0.30319.233
Foxtable 版本:2025.1.3.1
错误所在事件:窗口,客户及订单,DateTimePicker1,ValueChanged
详细错误信息:
无法在 System.DateTime 和 System.String 上执行“=”操作。
---------------------------------------------------------------------
去掉空格,也是提示出错。
------------------------------------------------
Dim dt As Date
dt = e.Form.Controls("DateTimePicker1").Value
If e.Form.Controls("CheckBox_quxiao").Checked Then
Tables("客户及订单_table_dingdan").Filter = "[日期]=#" & dt & "#"
Else
Tables("客户及订单_table_dingdan").Filter = "[日期]=#" & dt & "# And ([状态] <> '取消' or [状态] Is Null) "
End If
Tables("客户及订单_table_dingdan").sort = "产品,酒店 DESC"
Dim todaybeizhu As String
todaybeizhu = e.Form.Controls("DateTimePicker1").Value & ",总人数:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "") & "人,关外:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 = '关外'") & _
"人,镇上外店:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 <> '自驾' and 酒店 <> '关外' and 酒店 <> '皇冠' and 酒店 <> '蓝景' and 酒店 <> '希尔顿'and 酒店 <> '黄松浦' and 酒店 <> '山门' and 酒店 <> '半山' ") & _
"人,山门:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 = '皇冠' or 酒店 = '蓝景' or 酒店 = '希尔顿' or 酒店 = '黄松浦' or 酒店 = '山门' or 酒店 = '半山' ") & _
"人,自驾:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 = '自驾'") & _
"人,其他:" & Tables("客户及订单_table_dingdan").Compute("Sum(人数)", "酒店 is null ")
e.Form.Controls("TextBox4").value = todaybeizhu
Dim dr As DataRow
dr = DataTables("日汇总表").Find("[日期]=#" & e.Form.Controls("DateTimePicker1").Value & "#", "日期 Desc")
If dr IsNot Nothing Then
Dim wz As Integer = Tables("日汇总表").FindRow(dr)
If wz >= 0 Then
Tables("日汇总表").Position = wz
End If
Else
Tables("日汇总表").AddNew
Tables("日汇总表").current("日期") = e.Form.Controls("DateTimePicker1").Value
Tables("日汇总表").current("当日备注") = todaybeizhu '
End If
[此贴子已经被作者于2025/1/26 10:49:26编辑过]
那就判断一下
Dim dt As Date
dt = e.Form.Controls("DateTimePicker1").Value
If dt <> Nothing Then
其它代码
Else
MsgBox("没有选择日期")
End If